About Features Downloads Getting Started Documentation Events Support GitHub

Site Tools


configuration:static_pages

Static Pages

:!: This feature was introduced in VuFind 4.0

It is sometimes useful to host mostly-static HTML content pages within the framework of VuFind itself. The system provides a simple mechanism for serving arbitrary templates, including internationalization support.

Simple Example

For static content, simply create a new template inside the templates/content folder of your theme. You can then link to this content using the content-page route with the template name passed to the route as the 'page' parameter.

VuFind ships with an example FAQ template showing how to set up this simple scenario. The link to this page is:

<a href="<?=$this->url('content-page', ['page' => 'faq']) ?>"><?=$this->transEsc('FAQs')?></a>

It is also possible to display a content page in a lightbox by adding the data-lightbox attribute to the link:

<a href="<?=$this->url('content-page', ['page' => 'faq']) ?>" data-lightbox><?=$this->transEsc('FAQs')?></a>

Multi-language Example

The content system also supports i18n. If you create different versions of a template with filenames suffixed with a language code (e.g. faq_en.phtml, faq_de.phtml, etc.) VuFind will attempt to load the version matching the user's selected language. If no match is found, it will next attempt to load the template matching the configured default language. If that is not found, it will finally default to the non-suffixed version of the filename.

For an example, see the asklibrary.phtml and asklibrary_en.phtml templates in the content template folder.

Markdown Support

:!: This feature was introduced in VuFind 7.0.

If you prefer to build your content pages using Markdown instead of PHP templates, you can simply name the files you create under the templates/content directory of your theme with .md extensions instead of .phtml extensions, and they will be displayed appropriately. If you create both .phtml and .md files with the same base name, the .phtml file will take precedence over the .md file.

Embedding Static Content

There may be situations where you want to embed static content inside another custom template, instead of rendering it as a stand-alone page (for example, an “About Us” section on your home page, which you might choose to implement as a very simple content block with a custom template). Starting with VuFind 8.0, you can use the Content view helper to embed static content, with full support for the other features described here (i18n and Markdown rendering). If you follow the normal conventions for creating content, you can simply use:

<?=$this->content()->renderTranslated('contentPageName');

This will display the content of “contentPageName” inline, applying the usual internationalization conventions and searching all supported template formats. The renderTranslated method also accepts several additional parameters which can be used to customize the behavior, in case you want to search a different template directory or apply a different naming convention. You can refer to the Content helper's source code for details. An example of advanced features in action can be found in the HelpText view helper, which now uses the Content helper's advanced features to display VuFind's help pages.

Video

This topic is discussed in the Managing Static Content tutorial video.

configuration/static_pages.txt · Last modified: 2021/11/09 11:33 by demiankatz