In any programming language, if you find yourself frequently repeating a chunk of code or evaluating an expression, that means it's time to put it in to a function or variable, respectively.
Symphony 1.7 has an area known as Utilities. Each utility contains a set of related code to be applied at runtime. For code that should be applied to every page request, we then turn to Masters. Most of my projects have a few common variables that I use throughout the website so I place those variable definitions in the Master.
I find myself frequently evaluating an expression to see if a user is logged in on Symphony. Placing the expression in a variable will require it to only be evaluated once, plus you can reference the result anywhere in your code. Add this line of code to your Master:
<xsl:variable name="IsLoggedIn" select="/data/events/user[@logged-in = 'true']" />
This will assign to the "IsLoggedIn" variable a boolean value relating to the visitor's login status. Don't forget to also make sure that the "Login Info" Event is attached or this will always return false. This is useful for showing information only to your registered users.
<xsl:if test="IsLoggedIn">
<xsl:text>Welcome back, </xsl:text>
<xsl:value-of select="/data/events/user/username" />
</xsl:if>
More to come later.
No comments have been made.