Permalink
Browse files

core: catinclude also accepts a list of atoms instead of an id

This makes it in the admin again possible to override the
`_admin_overview_list.tpl` file based on the category that is
selected. This restores the functionality that was removed in commit
1d715af, but now implemented in a
different, more explicit way.

Documentation for the new `m.category[222].is_a` option and the extra
feature of `catinclude` is provided.
  • Loading branch information...
1 parent b539b56 commit dc24180ee1cebc495e8c69200ebb053ffbf6006f @arjan arjan committed Mar 30, 2013
@@ -123,10 +123,15 @@ category, they are accessed by id or category name. For example::
| |up to the children of the | |
| |children. | |
+----------+--------------------------------+-------------------------------------+
-|path |List of parent categories from |[ 104, 106 ] |
+|path |List of parent category ids from|[ 104, 106 ] |
| |the root till the category, | |
| |excluding the indexing category.| |
+----------+--------------------------------+-------------------------------------+
+|is_a |List of the parent category |[ text, article, news ] |
+| |names form the root till the | |
+| |category, including the current | |
+| |category. | |
++----------+--------------------------------+-------------------------------------+
|image |A random depiction for this |<<"2009/10/20/flat-world-proof.jpg">>|
| |category. The returned image | |
| |filename comes from one of the | |
@@ -28,6 +28,18 @@ The tag accepts extra arguments, which will be passed as template variables to t
The resource id will be available in the included template as the variable `id`.
+Instead of passing an id, you can also pass in a list of category
+names which are to be search for. These names need to be atoms, like
+this::
+
+ {% catinclude "hello.tpl" [`text`, `article`] %}
+
+This will search for the following templates, in order::
+
+ hello.article.tpl
+ hello.text.tpl
+ hello.tpl
+
See the :ref:`tag-include` for caching options and argument handling.
.. seealso:: :ref:`tag-all-catinclude`, which is useful to include multiple templates.
@@ -52,7 +52,7 @@
</div>
{% with m.search.paged[{query authoritative=1 cat=q.qcat text=q.qs page=q.page sort=q.qsort|default:"-modified"}] as result %}
- {% include "_admin_overview_list.tpl" result=result %}
+ {% catinclude "_admin_overview_list.tpl" m.category[q.qcat].is_a result=result %}
{% pager result=result dispatch="admin_overview_rsc" qargs hide_single_page=1 %}
{% endwith %}
@@ -99,6 +99,8 @@ m_find_value(tree2, #m{value={cat, Id}}, Context) ->
tree_depth(Id, 2, Context);
m_find_value(path, #m{value={cat, Id}}, Context) ->
get_path(Id, Context);
+m_find_value(is_a, #m{value={cat, Id}}, Context) ->
+ is_a(Id, Context);
m_find_value(image, #m{value={cat, Id}}, Context) ->
image(Id, Context);
m_find_value(all_flat, #m{value={cat, Id}}, Context) ->
@@ -195,12 +195,16 @@ find_template_cat([$/|_] = File, _Id, _Context) ->
{ok, File};
find_template_cat(File, None, Context) when None =:= <<>>; None =:= undefined; None =:= [] ->
find_template(File, Context);
+find_template_cat(File, [Item|_]=Stack, Context) when is_atom(Item) ->
+ find_template_cat_stack(File, Stack, Context);
find_template_cat(File, Id, Context) ->
Stack = case {m_rsc:is_a(Id, Context), m_rsc:p(Id, name, Context)} of
{L, undefined} -> L;
- {[meta, category|_] = L, _Name} -> L;
{L, Name} -> L ++ [z_convert:to_atom(Name)]
end,
+ find_template_cat_stack(File, Stack, Context).
+
+find_template_cat_stack(File, Stack, Context) ->
Root = z_convert:to_list(filename:rootname(File)),
Ext = z_convert:to_list(filename:extension(File)),
case lists:foldr(fun(Cat, {error, enoent}) ->

0 comments on commit dc24180

Please sign in to comment.