Dynamic Attribute: Show no longer works

I had some output set to only display when the user is logged in (it’s actually a ‘Log Out’ link in the nav menu) which was working fine but now isn’t so I’m assuming it’s a bug introduced in the latest version.

The code generated is this:

<li class="nav-item" dmx-show="$_SESSION['siteSecurityId']">
  <a class="nav-link" href="logout.php">Log out</a> 
</li> 

I thought I was going mad and then wondered if it’s a new bug.

Not sure if it is a solution but have tried setting a full condition rather than an implied one:

$_SESSION[‘siteSecurityId’] != Null

or even

$_SESSION[‘siteSecurityId’] != ‘’ (in case then session is set but to empty string now rather than null)

Thanks, @Hyperbytes, but I’ve already tried that. I also output the session variable to check it had a value and it does.

1 Like

For now I’ve hard-coded some PHP:

<?php if(isset($_SESSION['siteSecurityId'])) { ?>
                          <li class="nav-item">
                            <a class="nav-link" href="logout.php">Log out</a> 
                          </li>                             
<?php } ?>

but I’d rather do it the Wappler way.

1 Like

But that’s not the way to check this. You cannot check session like this with this syntax in a dmx-show attribute.
You need to access the logged user ID from the security provider step in your server action, which returns the logged user details, just like explained here:
https://community.wappler.io/t/getting-details-of-the-logged-in-user-and-binding-them-to-your-page/2850/2

I think this may be the source of the confusion

Yes but you use this wrapped with PHP tags, in some PHP code - not just randomly placing it on your pages.
The same way you cannot just place echo('test') on the page and expect it to work without the PHP tags around it.

you are of course correct, using the security provider rather than pho sessions is the correct way to do it

This should also be working:

dmx-show="<?php isset($_SESSION[‘siteSecurityId’]) ?>"
1 Like

Brilliant. That was the instructions I needed:

https://community.wappler.io/t/getting-details-of-the-logged-in-user-and-binding-them-to-your-page/2850/2

I’ve gone through all the steps and can now set it to show when logged in and it’s all done the Wappler way. Happy days.

Huge thanks.

1 Like

I suppose to be technical the correct way in Wappler is via site security and reference to the sitesecurity.identity variable as described in the below post rather than using session variables:

Agreed @Hyperbytes, rather use the correct Wappler way and avoid all the confusion while at the same time making sure all your bindings work correctly and everything is accessable within the interface instead of using custom php and then having to try get Wappler to know what are doing.

1 Like