Skip to content

Instantly share code, notes, and snippets.

@mickadoo
Last active May 14, 2018 15:37
Show Gist options
  • Save mickadoo/f38e122793e91274c876b27a8fb32384 to your computer and use it in GitHub Desktop.
Save mickadoo/f38e122793e91274c876b27a8fb32384 to your computer and use it in GitHub Desktop.
Options for having global template variables

Write a smarty modifier to check permission

✔️ flexible solution that can be used for any future permission
❌ the modifier format is confusing, most people would probably expect a function call instead

{if 'access CiviCRM'|permissionCheck }
  <!-- Do something -->
{/if}

Write a smarty function to set global variables

✔️ can use the variables easily and call the function whenever we need it
❌ anyone looking at the code might not be sure where the permission variables are coming from
❌ having a over-general init function could become messy
❌ not flexible, new permission checks require new variables

{ initGlobalVariables() }
{if $canAccessCiviCRM}
  <!-- Do something -->
{/if}

Use some global variables somewhere

These would need to be set somewhere that was always called, I thought of the config hook but it seems to be a waste to call this every time and there are problems I found with autoloading classes used in this code from the config hook.

✔️ have a single place to define global template variables
❌ bugs with autoloading
❌ variables used in CiviHR will be defined in SSP
❌ performance
❌ not flexible, new permission checks require new variables

Use the session variable

It's possible to set some variables in CRM_Core_Session, such as $isRoot. This would probably mean setting these in civihr_employee_portal after logging in.

✔️ performance
❌ again splitting stuff used in CiviHR that is defined in SSP
❌ not flexible, new permission checks require new variables

{if $session->get('canAccessCiviCRM') }
  <!-- Do something -->
{/if}
@omarabuhussein
Copy link

despite the cons u mentioned, I see that the first option is fine enough unlike the others which looks very messy to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment