Shortcodes:Prerender Shortcode
From e107 Wiki
e107 Wiki: English | Русский | Deutsch | Français | Magyar | Português | Български | Česky | Nederlands | Ελληνικά | Italiano | Norske | Polska | Slovenščina | Español | Svenska | Translate: Wiki | Page
Pre-rendering shortcodes Some shortcodes can be pre-rendered in your theme.php or admin_template.php etc, so you can alter your themes output based on what is contained within your pre-renders. This is best illustrated with an example... In the admin area you will have noticed that after 30 days a menu appears that warns you that your password hasn't been updated and that you should now recreate it. This menu is rendered by the shortcode {ADMIN_PWORD} which is found in your admin_template.php. Perhaps you feel that the warning isn't strong enough and you want to display a big red warning message graphic above the menu when it is displayed. If you were to do the following code in your admin_template.php you will quickly notice a problem: 1. $ADMIN_HEADER .= "<img src='big_red_warning.png' /> {ADMIN_PWORD}";
A way round this problem would be to pre-render the shortcode so you can test if its active and if so display your graphic and if not, don't display it. The first step then is to do the pre-render: 1. $admin_password = $tp -> parseTemplate('{ADMIN_PWORD}');
If the menu isn't to be displayed, this variable wont contain any data - i.e. it will be an empty string: "". Now we know this information we can create a rule when building our $ADMIN_HEADER to determine if the $admin_password variable contains the menu or an empty string and if it does we display our big red warning graphic, if it doesn't we don't display the graphic. Here's the code: 1. $admin_password = $tp -> parseTemplate('{ADMIN_PWORD}');
2.
3. if ($admin_password!="") {
4. $ADMIN_HEADER .= "<img src='big_red_warning.png' /> ".$admin_password;
5. }
Obviously, you need to know PHP to take full advantage of pre-rendering, but this additional feature will allow you to create truly dynamic themes. | |||||||

