ikiwiki/doc/bugs/template_creation_error.mdwn

112 lines
4.1 KiB
Plaintext
Raw Normal View History

2013-02-23 01:38:28 +01:00
Hi,
I am trying to build a template. The compilation of this template results in a weird exception. I have isolated the cause of the exception to the following point:
If i have this in the template code:
\[[!inline<br/>
pages="\<TMPL_VAR SEL_PAGES\>"<br/>
template=extract-entry<br/>
\]]<br/>
There is no problem at all. I can use the template with the desired result. But if I try to use this (just adding the "show" parameter):
\[[!inline <br/>
pages="\<TMPL_VAR SEL_PAGES>"<br/>
template=extract-entry<br/>
show=\<TMPL_VAR CNTPG><br/>
\]]<br/>
I get this exception on the Git bash console:
<pre>
$ git push
Counting objects: 7, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 410 bytes, done.
Total 4 (delta 3), reused 0 (delta 0)
remote: From /home/b-odelama-com/source
remote: eb1421e..5e1bac5 master -> origin/master
remote: Argument "\x{3c}\x{54}..." isn't numeric in numeric lt (<) at /usr/share/perl5/IkiWiki/Plugin/inline.pm line 231.
remote: Argument "\x{3c}\x{54}..." isn't numeric in numeric lt (<) at /usr/share/perl5/IkiWiki/Plugin/inline.pm line 231.
To ssh://b-odelama-com@odelama-com.branchable.com/
eb1421e..5e1bac5 master -> master
</pre>
Please, let me know what to do to avoid this kind of error.
> When you add a template page `templates/foo.mdwn` for use
> the [[ikiwiki/directive/template]] directive, two things happen:
>
> 1. `\[[!template id=foo ...]]` becomes available;
> 2. a wiki page `templates/foo` is built, resulting in a HTML file,
> typically `templates/foo/index.html`
>
> The warnings you're seeing are the second of these: when ikiwiki
> tries to process `templates/foo.mdwn` as an ordinary page, without
> interpreting the `<TMPL_VAR>` directives, `inline` receives invalid
> input.
>
> This is a bit of a design flaw in [[plugins/template]] and
> [[plugins/edittemplate]], I think - ideally it would be possible to
> avoid parts of the page being interpreted when the page is being
> rendered normally rather than being used as a template.
>
> There *is* a trick to avoid parts of the page being interpreted when
> the page is being used as a template, while having them appear
> when it's rendered as a page:
>
> <TMPL_IF FALSE>
> <!-- This part only appears when being used as a page.
> It assumes that you never set FALSE to a true value :-) -->
> \[[!meta robots="noindex,nofollow"]]
> This template is used to describe a thing. Parameters:
> * name: the name of the thing
> * size: the size of the thing
> </TMPL_IF>
>
> The thing is called <TMPL_VAR name> and its size is <TMPL_VAR size>
>
> I suppose you could maybe extend that to something like this:
>
> <TMPL_IF FALSE>
> <!-- This part only appears when being used as a page.
> It assumes that you never set FALSE to a true value :-) -->
> \[[!meta robots="noindex,nofollow"]]
> This template is used to describe a thing. Parameters:
> * name: the name of the thing
> * size: the size of the thing
> </TMPL_IF>
>
> <TMPL_IF FALSE>
> \[[!if test="included() and !included()" then="""
> </TMPL_IF>
> <!-- This part only appears when being used as a template. It also
> assumes that you never set FALSE to a true value, and it
> relies on the [[ikiwiki/pagespec]] "included() and !included()"
> never being true. -->
> The thing is called <TMPL_VAR name> and its size is <TMPL_VAR size>
> <TMPL_IF FALSE>
> """]]
> </TMPL_IF>
>
> but that's far harder than it ought to be!
>
> Perhaps the right solution would be to change how the template plugin
> works, so that templates are expected to contain a new `definetemplate`
> directive:
>
> This template is used to describe a thing. Parameters:
> * name: the name of the thing
> * size: the size of the thing
>
> \[[!definetemplate """
> The thing is called <TMPL_VAR name> and its size is <TMPL_VAR size>
> """]]
>
> with templates not containing a `\[[!definetemplate]]` being treated
> as if the whole text of the page was copied into a `\[[!definetemplate]]`,
> for backwards compatibility?
>
> --[[smcv]]