Static HTML Web Part Properties

ana mark asked on October 25, 2018 16:55

In Static HTML Webpart - i have a condition in Visibility check

{% custommacro.GetID() != null && custommacro.GetWorkerID() != null #%}

however it is not toggling the visibility in the webpart.. am i missing something

Recent Answers


Peter Mogilnitski answered on October 25, 2018 18:17 (last edited on December 10, 2019 02:31)

Syntax looks OK, but check the event log first. if there nothing in there add another static text web part to your page and print those in here :

ID: {% custommacro.GetID() |(identity)GlobalAdministrator%}<br>
1 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on October 25, 2018 20:50

Debug your macro to make sure it's returning the values you're expecting. It may be returning an empty string and not NULL which are different checks in your statement.

2 votesVote for this answer Mark as a Correct answer

ana mark answered on October 26, 2018 15:49 (last edited on December 10, 2019 02:31)

Hi Peter and Brenden .. Thanks for your quick reply ..

Yeah macro is returning empty string .. so, i changed the check to

Code {% !IfEmpty(custommacro.GetWorkerID()) |(identity)GlobalAdministrator%} 

but still expression is throwing error message in the event log

Error while evaluating expression: custommacro.GetPollWorkerID() |(user)sxzza|(hash)ef529c5cb5ebed31ae33b87a44789a8a4f60edf643ae3f3fe4e6e3f91e1339f6

System.InvalidOperationException: Sequence contains no elements

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on October 26, 2018 15:58

What does your full macro code look like?

0 votesVote for this answer Mark as a Correct answer

ana mark answered on October 26, 2018 16:05 (last edited on October 26, 2018 16:07)

It has a sql statement

Code public WorkerInfo GetWorkerID()
    {
        var ID = HttpContext.Current.Session["VidSession"].ToString();

        var sqlQuery = @" SELECT  WorkerID  FROM tblWorker  where Vid=" + ID;


        var setting = _databaseQueryer.ExecuteDatabaseQuery(connection => connection.QuerySingle<WorkerInfo>(sqlQuery));

            return setting;
    }
0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on October 26, 2018 16:12

It doesn't look like you're registering your custom macro properly. Take a look at the documentation.

0 votesVote for this answer Mark as a Correct answer

ana mark answered on October 26, 2018 16:30

The above code is helperclass that is where i am getting the value .. below is the code where i am registering the macro

Code [MacroMethod(typeof(string), "Gets worker id", 1)]
     [MacroMethodParam(1, "value", typeof(string), "x")]
     public static string GetWorkerID(EvaluationContext context, params object[] parameters)
     {

       WokerIDHelper WorkerIDSetting = new WokerIDHelper();


    var settings = WorkerIDSetting.GetWorkerID().WorkerID;

    return settings.ToString();

}
0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on October 26, 2018 16:40

Unless you've registered a namespace, simply use:

GetWorkerID()

1 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.