\chapter{Timber extension}\label{ch:timber}

From \href{https://timber.github.io/docs/v2/}{Timber documentation}:

\begin{quotation}
Timber helps you create fully-customized WordPress themes faster with more sustainable code.
With Timber, you write your HTML with the Twig Template Engine. This cleans up your theme code. Your PHP file can focus on providing the data or logic and your Twig files can focus 100\% on the HTML and display.
\end{quotation}

At Romhack Plaza, we decided to separate the content from the form as much as possible by using Timber templates.
We therefore added new features to Timber via our plugin.
Most of them can be found in the \dir{src/Extenders/Timber} file.

\begin{warnbox}
    Timber is included in \WP via the \emph{\rhpz theme} and not by the plugin! You must enable the \rhpz theme to have access to each of these functions.%
\end{warnbox}

\section{Views}\label{sec:views}

\rhpz plugin add a new view location folder: \dir*{views} at the root of the plugin folder.
\lstinputlisting[label=lst:view-def,includerangemarker=false,linerange={<start_add_views>-<end_add_views>}]{../src/Extenders/Timber.php}

If you want render a template file from that folder, you can specify the folder with "@plugin":
\lstinputlisting[label=lst:view-usage,linerange=2-2]{examples/timber.php}

\section{Functions}\label{sec:timber-funcs}

Some functions have been added to use them in a Timber template.

\subsection{svg\_icon}\label{subsec:svg-icon}
\begin{sourcedef}{../src/Extenders/Timber.php}{<start_svg_icon>}{<end_svg_icon>}

    \sourceargs{
        \item\lstinline|string icon_id|
    }

    \sourceexample{examples/twig-examples.twig}{1}{1}

    Call the \lstinline|svg_icon| snippet from the \rhpz theme.
    The SVG icon list is from \href{https://genericons.com/}{genericons neue}.
    If the theme is not enabled, this callable return an empty string.

\end{sourcedef}

\subsection{theme\_setting}\label{subsec:theme_setting}
\begin{sourcedef}{../src/Extenders/Timber.php}{<start_theme_setting>}{<end_theme_setting>}

    \sourceargs{
        \item\lstinline|string option_name|
    }

    \sourcereturn{
        \item\lstinline|mixed| If not found, return \lstinline|false|.
    }

    \sourceexample{examples/twig-examples.twig}{2}{2}

    Call the \lstinline|$_romhackplaza_theme->settings->get()$| from the \rhpz theme.
    Get a setting registered from the theme\footnote{Every settings linked to Customizer.}.
    If the theme is not enabled, this callable return an empty string.

\end{sourcedef}

\section{Conditional tags}\label{sec:cond-tags}

Some \href{https://codex.wordpress.org/Conditional_Tags}{conditional tags} are added to the \href{https://timber.github.io/docs/v2/guides/context/}{Timber context}:
\lstinputlisting[label=lst:cond-tags,includerangemarker=false,linerange={<start_cond_tags>-<end_cond_tags>}]{../src/Extenders/Timber.php}

\sourceexample{examples/twig-examples.twig}{3}{5}



