Skip to main content
Topic: template functions (Read 2602 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

template functions

Suppose for a moment one wanted to rework the templates.  Like all of them.  Maybe even add a few additional functions to existing templates.  Where would the new function call need to be added?  What about entirely new actions, where would those need to be loaded and called? 

This may be an overly ambitious project.  Still, there may be attempts at forward progress until it either happens or becomes overly daunting.  Lol!  Thanks, hope everyone has a great weekend!

Re: template functions

Reply #1

For templates, you can simply copy default in creating new theme and copy all its templates. That way you can recreate the template based on default theme.

I think additional functions can be created in any particular templates and then call respectively.

With regards to actions you want to create an addon for it or make modification to default source files. The later is not advisable though.

You want to refer to @inter flarum style addon on how he change default BoardIndex template to FlarumSyle template without modification.

Re: template functions

Reply #2

Quote from: badmonkey – Suppose for a moment one wanted to rework the templates.  Like all of them.  Maybe even add a few additional functions to existing templates.  Where would the new function call need to be added?  What about entirely new actions, where would those need to be loaded and called? 
This is a quite generic question... much more detail is needed in order to give a "good" answer I think.
First, there is to define exactly what you mean with "templates", because unfortunately, in Elk (and previous) the term may refers to two things: the file containing all the functions for rendering a particular page, any of the functions contained in one of the previous files.
Bugs creator.
Features destroyer.
Template killer.

Re: template functions

Reply #3

What I'm thinking is changing everything about the layout and navigation.  All of it.  More or less that means changing both template tiers....function level as well as file level.

But to simplify the question, let's say hypothetically there is to be a whole new function to be created in the who's online action.  That action contains a couple of functions already.  The online list itself, and the credits.  So if we were to add function foo, where would it be loaded and called in order to be rendered in the page?

Re: template functions

Reply #4

If I got it right, the answer may look like: "source" (i.e. anything contained in the "sources" directory) has few... things that cannot be changed by the theme, and are the names of some functions.
These names are just the "sub-templates" and the "layers" referenced within the code.
So, for example, the function "template_boards_list" shall be present (because "boards_list" is the sub-template used by the BoardIndex controller).
That said, what this function does... well, it's up to the themer. You can even decide to leave it empty.
This is anyway only partially true, in theory you could change the name of the sub-template from within the theme, but that's a bit hackish at the moment and inconsistent across templates, so it may work in one place, but not in another, so I'll not describe how to do it.

Following your example (and based only on the names of the functions/files), I would say that:
1) you have to look into the "Who.template.php" file,
2) template_whos_online is responsible for the main list of members on line (so it's a sub-template and is the one called to render the page and shall stay),
3) template_whos_selection_above and template_whos_selection_below (based on the fact the functions end in "_above" and "_below") are a "layer" added around the sub-template, they could stay or not, it's not important.

So, to create a completely new page, the only thing you are forced to maintain is a function called "template_whos_online", then you can create inside Who.template.php almost any other function you want, and you can call those functions from anywhere you like (speaking about the who is online page).
Bugs creator.
Features destroyer.
Template killer.