Jump to content
  • 0

Parser functions in templates


Guest Charles-François Dallaire

Question

Guest Charles-François Dallaire

Hi,

Trying to validate if a parameter is empty, if it does output nothing (the ":" in this case), if it contains information output it (:{{{1}}}).

My Template as of now :

:{{{1}}}

If the information is empty it does the line break from the ":" and this is what I don't want.

What I was thinking to correct my problem, but it doesn't work :

{{#if:	{{{1}}}	|	{{1|:{{{1}}}|}}	|	{{blank}} }}

1 is a variable like Contact_Name if it helps.

Thanks !

 

Charles

Link to comment
Share on other sites

10 answers to this question

Recommended Posts

  • 1
8 minutes ago, Charles-François D. said:

Okay, so I have redone my infobox to look like this :


{{#if:    {{{Contact_Cie|}}}     |
==={{{Contact_Cie}}}===
}}<!--
-->{{#if:    {{{Contact_Name|}}}    |
:Name : {{{Contact_Name}}} }}<!--
-->{{#if:    {{{Contact_Tel|}}}     |
:Tel : {{{Contact_Tel}}} }}

But it still does the line break if no information is entered in the name or tel field...

Something i'm not fully understanding, i'm very greatfull of your help !

 

Charles

I edited your template code above -- you had line breaks in-between the if statements which were being rendered. I commented them out with <!-- --> so that you retain the visual spacing (for readability when editing) but the line breaks themselves do not appear when the template is used. I also put the header on a line by itself, as otherwise it could cause issues in some template invocations.

  • Thanks 1
Link to comment
Share on other sites

  • 0

Add a pipe at the end of the parameter name:

{{{1|default value if this parameter isn't specified}}}
{{{1|}}} (blank default value)

Will output the value of {{{1}}} if specified, and whatever is after the pipe (nothing in the case you want, so that second line above).

(Side note: if you sign up for an account, you can post without needing mod approval, and you can do things like upvote and mark things as best answers)

Link to comment
Share on other sites

  • 0
Guest Charles-François Dallaire

Hi,

If the output need to contain the ":" to indent the content passed in parameter do you know where I should put it ?

Thanks ! and i'll do so ;)

 

Charles

Link to comment
Share on other sites

  • 0

Hi,

It still doesn't work, let say I have an infobox containing this line :

{{#if:    {{{Contact_Name}}}           |     {{Contact_Name|{{{Contact_Name}}}|}}          |  {{blank}} }}

And It uses this template for Contact_Name :

{{#if: {{{1|}}} |
:Name : {{{1}}} }}

And doesn't insert a name when using the infobox the line break from the ":" still appear.

Infobox :

{{Infobox/Contact
|Contact_Name=
|Contact_Cie=Blabla
|Contact_Tel=123-456-7890
}}

The Output is :

===Blabla===
:
:123-456-7890

Thanks !

 

Charles

Link to comment
Share on other sites

  • 0

Replace 1 with the name of the parameter, in your case Contact_Name. Do not use a sub-template, you don't need it for something this simple.

{{#if: {{{Contact_Name|}}} |
: {{{Contact_Name}}} }}

The pipe at the end in the first parameter of #if is very important. If you do not have the pipe at the end, it will not default to blank, and therefore it will always try to execute the "then" clause of the if.

You do not need an "else" clause with {{blank}} unless Template:Blank actually has contents (and isn't just empty). Omitting the "else" clause will automatically make it blank.

Link to comment
Share on other sites

  • 0
9 minutes ago, Charles-François D. said:

Not sure to understand. you recommend to replace :


{{#if:    {{{Contact_Name}}}           |     {{Contact_Name|{{{Contact_Name}}}|}}          |  {{blank}} }}

For this :


{{#if: {{{Contact_Name|}}} |
: {{{Contact_Name}}} }}

Without the sub-template or the blank part at the end of the if ?

 

Thank you very much for your time !

 

Charles

 

Yep. Replace that entire existing line with what I just said. No sub-template or blank.

Link to comment
Share on other sites

  • 0

Okay, so I have redone my infobox to look like this :

{{#if:    {{{Contact_Cie|}}}     |
==={{{Contact_Cie}}}=== }}
{{#if:    {{{Contact_Name|}}}    |
:Name : {{{Contact_Name}}} }}
{{#if:    {{{Contact_Tel|}}}     |
:Tel : {{{Contact_Tel}}} }}

But it still does the line break if no information is entered in the name or tel field...

Something i'm not fully understanding, i'm very greatfull of your help !

 

Charles

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.