





















































Let us learn our need of PHx by building a new functionality for our site that lets us add profiles of our family members and friends. We will add a new page called 'Family and Friends' that will show the list of all the individuals that we add. Once the user clicks on an individual, it will show certain details such as name, relationship to you, occupation, web site. This is easy to implement; all we have to do is create the template variables for each of the fields, and create a template that uses these template variables. So, to display the Occupation, the template will have a code similar to the following:
Occupation: [*occupation*]
Though this might appear to work initially, it has a small glitch in it. When we are entering the personal details of an individual, we may not want to enter all of the values for every individual. In the case of not having a value for the variable, it looks cleaner to not show the label at all instead of leaving it blank. In our case—if we have no value for occupation—it will look cleaner to not show the label Occupation. So here comes a need for displaying certain text only if the template variable—in this case, occupation—has a value. We can do this using PHx without having to write a snippet.
To download PHx, use the following steps:
Field Name |
Field Value |
Plugin Name |
PHx |
Plugin Code |
Contents of the file phx.plugin.txt in the extracted folder |
System Events | OnParseDocument |
Checked |
6.Click on Save.
Let us create a page that lists all the members from the Family or Friends group. This document will be a container that will have a document for each member that you would like to add. Hence, just as you have learned earlier, a call to the Ditto snippet can get you all the documents that a container holds.
Field Name |
Field Value |
|
Title |
Family and Friends |
|
Uses template |
Learning MODx default template |
<ul>
[!Ditto? &parents=`65` &tpl=`familyandfriendslist`!]
</ul>
Here, 65 is the ID of the created document. We give the ID of this document here as we will be adding the other documents as child documents of this document.
Field Name |
Field Value |
Chunk name |
familyandfriendslist |
Existing Category |
Learning MODx |
Chunk Code |
<li> <h3><a href="[~[+id+]~]">[+title+]</a></h3> </li> |