Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6349041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:32:19+00:00 2026-05-24T21:32:19+00:00

I am writing my own administration and, off course I am using Smarty. Now,

  • 0

I am writing my own administration and, off course I am using Smarty.
Now, what I would like to do is to add a access check function much similar to the {if} tag.

What I would like to write is:

{userAccess module='MyModule' action='WriteMessage'}
Yeey.. I can write something. My name is {$myName}.
{/userAccess}

but I can’t figure out how to. Can someone please point me into the right direction?
Also, if possible adding and {else} to it. So the code would be:

{userAccess module='MyModule' action='WriteMessage'}
Yeey.. I can write something. My name is {$myName}.
{else}
Nooo.. :( I don't have access.
{/userAccess}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T21:32:20+00:00Added an answer on May 24, 2026 at 9:32 pm

    I solved it creating my own “internal” function for smarty. This might not be the way Smarty intended it to be used, but it sure works for me… which is the most important thing for me.

    This is my end result:

    <?php
    /**
     * Smarty Internal Plugin Compile UserAccess
     * 
     * Compiles the {useraccess} {useraccesselse} {/useraccess} tags
     * 
     * @package Smarty
     * @subpackage Compiler
     * @author Paul Peelen
     */
    
    /**
     * Smarty Internal Plugin Compile useraccess Class
     */
    class Smarty_Internal_Compile_useraccess extends Smarty_Internal_CompileBase {
        // attribute definitions
        public $required_attributes = array('module', 'action');
        public $optional_attributes = array('userid');                  // Not yet implemented
        public $shorttag_order = array('module','action','userid');
    
        /**
         * Compiles code for the {useraccess} tag
         * 
         * @param array $args array with attributes module parser
         * @param object $compiler compiler object
         * @param array $parameter array with compilation parameter
         * @return string compiled code
         */
        public function compile($args, $compiler, $parameter)
        {
            $this->compiler = $compiler;
            $tpl = $compiler->template; 
            // check and get attributes
            $_attr = $this->_get_attributes($args);
    
            $module = $_attr['module'];
            $action = $_attr['action'];
    
            if (!is_string($module) || !is_string($action))
            {
                exit ("ERROR");
            }
    
            $this->_open_tag('useraccess', array('useraccess', $this->compiler->nocache, $module, $action));
            $this->compiler->nocache = $this->compiler->nocache | $this->compiler->tag_nocache;
    
            $output = "<?php ";
            $output .= "\$oAuth = \$GLOBALS['oAuth'];\n";
            $output .= " \$_smarty_tpl->tpl_vars[$module] = new Smarty_Variable;\n";
            $compiler->local_var[$module] = true;
    
            $output .= " \$_smarty_tpl->tpl_vars[$action] = new Smarty_Variable;\n";
            $compiler->local_var[$action] = true;
    
            $output .= "if (\$oAuth->getUserSubRights($action,$module)) {";
            $output .= "?>";
    
            return $output;
        } 
    } 
    
    /**
     * Smarty Internal Plugin Compile UserAccessElse Class
     */
    class Smarty_Internal_Compile_UserAccessElse extends Smarty_Internal_CompileBase {
        /**
         * Compiles code for the {useraccesselse} tag
         * 
         * @param array $args array with attributes module parser
         * @param object $compiler compiler object
         * @param array $parameter array with compilation parameter
         * @return string compiled code
         */
        public function compile($args, $compiler, $parameter)
        {
            $this->compiler = $compiler; 
            // check and get attributes
            $_attr = $this->_get_attributes($args);
    
            list($_open_tag, $nocache, $item, $key) = $this->_close_tag(array('useraccess'));
            $this->_open_tag('useraccesselse', array('useraccesselse', $nocache, $item, $key));
    
            return "<?php } else { ?>";
        } 
    } 
    
    /**
     * Smarty Internal Plugin Compile UserAccessclose Class
     */
    class Smarty_Internal_Compile_UserAccessclose extends Smarty_Internal_CompileBase {
        /**
         * Compiles code for the {/useraccess} tag
         * 
         * @param array $args array with attributes module parser
         * @param object $compiler compiler object
         * @param array $parameter array with compilation parameter
         * @return string compiled code
         */
        public function compile($args, $compiler, $parameter)
        {
            $this->compiler = $compiler; 
            // check and get attributes
            $_attr = $this->_get_attributes($args); 
            // must endblock be nocache?
            if ($this->compiler->nocache) {
                $this->compiler->tag_nocache = true;
            } 
    
            list($_open_tag, $this->compiler->nocache, $item, $key) = $this->_close_tag(array('useraccess', 'useraccesselse'));
            unset($compiler->local_var[$item]);
            if ($key != null) {
                unset($compiler->local_var[$key]);
            } 
    
            return "<?php } ?>";
        } 
    } 
    

    I hope this helps anybody who has this problem in the future.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing own switch class. I'd like to add a delegate to it -
I am writing my own Firebird database browser using the ibpp library. Is there
I am busy writing my own collection type and need to have a function
I'm currently writing my own virtual keyboard for linux using the X11 lib and
I am writing my own specific product crawler. Now there is a product selling
I'm considering writing my own delivery code using PowerShell and/or C#, maybe shelling to
I'm writing my own function in a different language, and I want it to
I am writing my own Custom Membership Provider but am using the Membership Providers
I'm writing my own ContentProvider which will be synced to a web service using
I'm writing my own Drupal 7 module, and like to use JQuery in it.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.