Forums | Mahara Community

Developers /
Access permission for page in Smarty


Sarah Cotton's profile picture
Posts: 7

23 September 2016, 23:25

Hi All

I'm trying to find a way to check whether a page is public or not from within a Smarty template but having trouble finding where to get this info from.

What I need is something like

{if !$public}

Do whatever

{/if}

If it helps I'm trying to access this from \theme\mytheme\templates\header.tpl

Any help would be much appreciated!

26 September 2016, 9:50

Hi Sarah,

If you are meaning a public .php page like htdocs/about.php
then you can set public flag at top of the php file:

  define('PUBLIC', 1);

to indicate that this page can be viewed by logged out users. You then can add to the smarty call

  $smarty->assign('public', defined('PUBLIC'));

and that would give you a boolean for {$public} in the template (.tpl) as to whether this page is public or not.

If you are meaning a user created page (via Portfolio/Pages) then you would need to find out if the page has an access rule for displaying it to public

So you'd need the view id value for the page, say $viewid = '1234' then on php side go:

    $view = new View($viewid);
    $public = false;
    $viewaccess = $view->get_access();
    foreach ($viewaccess as $access) {
        if ($access['accesstype'] == 'public') {
            // you might also need to do some checking of the access start/stop dates as well
            $public = true;
        }
    }

Then with smarty go:

  $smarty->assign('public', $public);

and that would give you a boolean for {$public} in the template (.tpl) as to whether this page is public or not.

Hope that helps


Cheers

Robert

Sarah Cotton's profile picture
Posts: 7

26 September 2016, 21:28

Hi Robert

That's great, thank you so much for your help!

Sarah

3 results