3 min read

PHx in action

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.

Installing PHx

To download PHx, use the following steps:

  1. Download PHx from http://MODxcms.com/PHx-1006.html.
  2. Extract the contents of the downloaded file.
  3. Create a directory called phx in the assets/plugins folder of your MODx installation.
  4. Copy all the files within the extracted folder to the assets/plugins/phx folder.
  5. Create a new plug-in using the MODx Manager interface:
    • Click on the Manage Resources menu item in the Resources menu
    • Click on the Plugins tab
    • Click on the New Plugin link
    • Fill it with the following details:

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.

Adding Family and Friends documents

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.

  • Create a page with the following details:

Field Name

Field Value

Title

Family and Friends

Uses template

Learning MODx default template

  • Modify the page created in the previous step to have the following code. (Note that we need to know the ID of the created page for the code and hence, we are modifying it after creating it.)
      <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.

  • In the above Ditto call, we have indicated that we are using a custom chunk to control the appearance of the listing. Create a chunk with the following details, to show a neat list of the documents that represent a member with the title and a link to the document.

Field Name

Field Value

Chunk name

familyandfriendslist

Existing Category

Learning MODx

Chunk Code

<li>

<h3><a href=”[~[+id+]~]”>[+title+]</a></h3>

</li>

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here