Advanced Topics

Although the goal of PageFactory is to help non-technical users, you can extend it's functionality if you're willing to write a little code.

For the most part, PageFactory uses Jinja syntax to process templates. Jinja is a template engine for the Python programming language. You can write Jinja code in PageFactory templates and build some pretty complex content in the process.

Conditional Statements

Probably the most useful functionality you'll get from using Jinja is conditional statements. Say you only want to display certain information when a row in the spreadsheet contains a specific value. Conditionals are the answer.

Consider this example:

advanced-conditionals

Here, we check if the value in the spreadsheet column "conservation" is equal to "high". If it is, we display the text in between {% if conservation == "high" %} and {% endif %}. We also use the double bracket syntax {{ name }} to output the value in the "name" column in the spreadsheet.

So, for the California Condor, the output text would be:

Currently, conservation efforts for the California Condor is considered a high priority. We must protect the California Condor!

But for the Golden Eagle it would read:

Currently, conservation efforts for the Golden Eagle is considered a low priority.

Overall, conditionals are pretty simple, and basically tell the template "if this, do that." They're a great resource for avoiding duplicate or thin content with programmatic SEO, and they can even be nested.

If you feel comfortable with conditional statements, and want to try more advanced tactics, check out Jinja's full documentation. It provides guidance on implementing more complex functionality such as for loops and filters.