Using macro in page template layout to check if user is logged in

Ashutosh Pandey asked on May 6, 2020 09:03

I'm trying to hide a section in page template layout if a user is logged in.

I tried this but it is not working:

                <div class="col-md-12 text-center">
                    <p>With our fingers on the TechPulse,<br> bringing you your tomorrow, today.</p>
                    <a href="/register" class="btn-primary" style='{% CurrentUser.IsAuthenticated ? "display:none" : "display:block" #%}' >Register Now!</a>
                </div>

What can I do, tried to search but looks like macro works in transformation and not page templates :(

Recent Answers


Ashutosh Pandey answered on May 6, 2020 09:09 (last edited on May 6, 2020 09:10)

I tried like this, is there a better way?

                <div class="col-md-12 text-center">
                    <p>With our fingers on the TechPulse,<br> bringing you your tomorrow, today.</p>
                    <a href="/register" class="btn-primary" style="<%= CMS.Membership.MembershipContext.AuthenticatedUser != null && !CMS.Membership.MembershipContext.AuthenticatedUser.IsPublic() ? "display:none" : "display:inline-block" %>" >Register Now!</a>
                </div>
0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on May 6, 2020 09:18

Are you using HTML or ASCX layout? Note that macros are not supported in ASCX layouts. Based on your second post I assume you are using ASCX since you used the inline displaying expression. This is also not really recommended as it is really old, old way of doing things and you may face issue like described here.
I would recommend using HTML layout type and macros or, for this part of the layout use e.g. Static HTML web part and use macros inside it.

1 votesVote for this answer Mark as a Correct answer

Ashutosh Pandey answered on May 6, 2020 09:27

Hi, we have a 2 year old site with Kentico 10. The layout is using ASCX. It would be difficult to change for now. Thanks

0 votesVote for this answer Mark as a Correct answer

Sultan Ahmed answered on May 6, 2020 10:15

Then use ascx macro

<div class="col-md-12 text-center">
  <p>With our fingers on the TechPulse,<br> bringing you your tomorrow, today.</p>
  <a href="/register" class="btn-primary" style="<%= CMS.Membership.MembershipContext.AuthenticatedUser != null && !CMS.Membership.MembershipContext.AuthenticatedUser.IsPublic() ? "display:none" : "display:inline-block" %>" >Register Now!</a>
</div>
0 votesVote for this answer Mark as a Correct answer

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