Re: Skip line if undefined.

Sherwood Botsford <[email protected]> Sat, 31 Mar 2018 14:22:07 -0600
Newsgroups gmane.comp.lang.perl.modules.template-toolkit
Message-ID <CAOX=2F8OHM3kPgSNA_Q+wkj3475URz-jZwcN-OFoud_RigpzJA@mail.gmail.com>
--===============5581367616686605396==
Content-Type: multipart/alternative; boundary="94eb2c1a64a6c163bc0568bb1e41"

--94eb2c1a64a6c163bc0568bb1e41
Content-Type: text/plain; charset="UTF-8"

Answer is simple

In header.inc

[% IF FBimage != "" %]
  <meta property="og:image" content="$FBimage"/>
[% END %]

Sigh.

I wrote this close to 10 years ago.

Regards

Sherwood


On 31 March 2018 at 12:08, Sherwood Botsford <[email protected]> wrote:

>
> My web pages start with something like this:
>
> [% PROCESS header.inc
> Title = "Shelterbelt Production"
> Desc = "Walk through on the economics of producing large numbers of medium
> size trees for use in shelterbelt plantings."
> FBimage="$base/Images/AdPix/Trade_Show/2013-06-27_20-32-32.jpg"
>
> %]
>
> Note the FBimage variable.
>
> In Header.inc
>
> <?xml version="1.0" encoding="utf-8"?>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
>         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
>
> [% USE String %]
> [% USE MultiMarkdown %]
>
> [% pathchunks = template.name.split('/') ;
> chunks = pathchunks.max
> pathchunks.$chunks = pathchunks.last.replace('.tt2','.html');
> CurWebPage = '/' _ template.name.replace('.tt2','.html');
>
>     CurWebLink = base _ CurWebPage
> %]
>
>
> <head>
>   <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
>   <meta content="text/html; charset=UTF-8" http-equiv="content-type" />
> $ExtraMetaContent
>   <title>$Title</title>
>   <base href="$base" />
>   <meta name="description" content="$Desc" />
>
>   <meta property="og:site_name" content="Tree Farm for Sale"/>
>     <meta property="og:type" content="article"/>
>   <meta property="og:image" content="$FBimage"/>
>   <meta property="og:title" content="$Title"/>
>   <meta property="og:url" content="$CurWebLink "/>
>   <link rel="shortcut icon" href="/favicon.ico" type="image/vnd.microsoft.icon"
> />
>   <link type="text/css" href="/2col.css" rel="stylesheet" />
>   <link rel="canonical" href=$CurWebLink />
>   <meta name="viewport" content="width=device-width, initial-scale=1" />
>
>
> Ok.
>
> The problem occurs with the open graph FBimage tag.  If I don't define it
> in my header later then facebook uses no image at all when shared.
> Otherwise it will default to the first image on the page.
>
> How do I modify Header.inc so that it doesn't put in the line
>
>  <meta property="og:image" content="$FBimage"/>
>
> if FBimage isn't defined in the calling template?
>
>
>
> Regards
>
> Sherwood
>
>

--94eb2c1a64a6c163bc0568bb1e41
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_default" style=3D"font-family:&quot;ti=
mes new roman&quot;,serif">Answer is simple</div><div class=3D"gmail_defaul=
t" style=3D"font-family:&quot;times new roman&quot;,serif"><br></div><div c=
lass=3D"gmail_default" style=3D"font-family:&quot;times new roman&quot;,ser=
if">In header.inc</div><div class=3D"gmail_default" style=3D"font-family:&q=
uot;times new roman&quot;,serif"><br></div><div class=3D"gmail_default" sty=
le=3D"font-family:&quot;times new roman&quot;,serif"><div class=3D"gmail_de=
fault">[% IF FBimage !=3D &quot;&quot; %]</div><div class=3D"gmail_default"=
>=C2=A0 &lt;meta property=3D&quot;og:image&quot; content=3D&quot;$FBimage&q=
uot;/&gt;</div><div class=3D"gmail_default">[% END %]</div><div><br></div><=
div>Sigh.</div><div><br></div><div>I wrote this close to 10 years ago.=C2=
=A0=C2=A0</div></div></div><div class=3D"gmail_extra"><br clear=3D"all"><di=
v><div class=3D"gmail_signature" data-smartmail=3D"gmail_signature"><div di=
r=3D"ltr"><div><div dir=3D"ltr"><div><div dir=3D"ltr"><div>Regards</div><di=
v><br></div><div>Sherwood<br><br></div></div></div></div></div></div></div>=
</div>
<br><div class=3D"gmail_quote">On 31 March 2018 at 12:08, Sherwood Botsford=
 <span dir=3D"ltr">&lt;<a href=3D"mailto:[email protected]" target=3D"_b=
lank">[email protected]</a>&gt;</span> wrote:<br><blockquote class=3D"gm=
ail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-le=
ft:1ex"><div dir=3D"ltr"><div class=3D"gmail_default" style=3D"font-family:=
&quot;times new roman&quot;,serif"><br clear=3D"all"></div><div class=3D"gm=
ail_default" style=3D"font-family:&quot;times new roman&quot;,serif">My web=
 pages start with something like this:=C2=A0</div><div class=3D"gmail_defau=
lt" style=3D"font-family:&quot;times new roman&quot;,serif"><br></div><div =
class=3D"gmail_default"><div class=3D"gmail_default"><div class=3D"gmail_de=
fault"><font face=3D"times new roman, serif">[% PROCESS header.inc=C2=A0</f=
ont></div><div class=3D"gmail_default"><font face=3D"times new roman, serif=
"><span style=3D"white-space:pre-wrap">	</span>Title =3D &quot;Shelterbelt =
Production&quot;=C2=A0</font></div><div class=3D"gmail_default"><font face=
=3D"times new roman, serif"><span style=3D"white-space:pre-wrap">	</span>De=
sc =3D &quot;Walk through on the economics of producing large numbers of me=
dium size trees for use in shelterbelt plantings.&quot;</font></div><div cl=
ass=3D"gmail_default"><font face=3D"times new roman, serif"><span style=3D"=
white-space:pre-wrap">	</span>FBimage=3D&quot;$base/Images/AdPix/<wbr>Trade=
_Show/2013-06-27_20-32-<wbr>32.jpg&quot;</font></div><div class=3D"gmail_de=
fault"><font face=3D"times new roman, serif"><br></font></div><div class=3D=
"gmail_default"><font face=3D"times new roman, serif">%]</font></div><div c=
lass=3D"gmail_default"><font face=3D"times new roman, serif"><br></font></d=
iv><div class=3D"gmail_default"><font face=3D"times new roman, serif">Note =
the FBimage variable.</font></div><div class=3D"gmail_default"><font face=
=3D"times new roman, serif"><br></font></div><div class=3D"gmail_default"><=
font face=3D"times new roman, serif">In Header.inc</font></div><div class=
=3D"gmail_default"><font face=3D"times new roman, serif"><br></font></div><=
div class=3D"gmail_default"><font face=3D"times new roman, serif"><div clas=
s=3D"gmail_default">&lt;?xml version=3D&quot;1.0&quot; encoding=3D&quot;utf=
-8&quot;?&gt;</div><div class=3D"gmail_default">&lt;!DOCTYPE html PUBLIC &q=
uot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;</div><div class=3D"gmail_default=
">=C2=A0 =C2=A0 =C2=A0 =C2=A0 &quot;<a href=3D"http://www.w3.org/TR/xhtml1/=
DTD/xhtml1-strict.dtd" target=3D"_blank">http://www.w3.org/TR/xhtml1/<wbr>D=
TD/xhtml1-strict.dtd</a>&quot;&gt;</div><div class=3D"gmail_default">&lt;ht=
ml xmlns=3D&quot;<a href=3D"http://www.w3.org/1999/xhtml" target=3D"_blank"=
>http://www.w3.org/1999/<wbr>xhtml</a>&quot; xml:lang=3D&quot;en&quot; lang=
=3D&quot;en&quot;&gt;</div><div class=3D"gmail_default"><br></div><div clas=
s=3D"gmail_default">[% USE String %]</div><div class=3D"gmail_default">[% U=
SE MultiMarkdown %]</div><div class=3D"gmail_default"><br></div><div class=
=3D"gmail_default">[% pathchunks =3D template.name.split(&#39;/&#39;) ;</di=
v><div class=3D"gmail_default"><span style=3D"white-space:pre-wrap">	</span=
>chunks =3D pathchunks.max</div><div class=3D"gmail_default"><span style=3D=
"white-space:pre-wrap">	</span>pathchunks.$chunks =3D pathchunks.last.repla=
ce(&#39;.tt2&#39;<wbr>,&#39;.html&#39;);</div><div class=3D"gmail_default">=
<span style=3D"white-space:pre-wrap">	</span>CurWebPage =3D &#39;/&#39; _ t=
emplate.name.replace(&#39;.tt2&#39;,&#39;<wbr>.html&#39;);</div><div class=
=3D"gmail_default">=C2=A0 =C2=A0=C2=A0</div><div class=3D"gmail_default">=
=C2=A0 =C2=A0 CurWebLink =3D base _ CurWebPage</div><div class=3D"gmail_def=
ault">%]</div><div class=3D"gmail_default"><br></div><div class=3D"gmail_de=
fault">=C2=A0 =C2=A0</div><div class=3D"gmail_default">&lt;head&gt;</div><d=
iv class=3D"gmail_default">=C2=A0 &lt;meta http-equiv=3D&quot;Content-type&=
quot; content=3D&quot;text/html;charset=3D<wbr>UTF-8&quot; /&gt;</div><div =
class=3D"gmail_default">=C2=A0 &lt;meta content=3D&quot;text/html; charset=
=3DUTF-8&quot; http-equiv=3D&quot;content-type&quot; /&gt;</div><div class=
=3D"gmail_default"><span style=3D"white-space:pre-wrap">	</span>$ExtraMetaC=
ontent</div><div class=3D"gmail_default">=C2=A0 &lt;title&gt;$Title&lt;/tit=
le&gt;</div><div class=3D"gmail_default">=C2=A0 &lt;base href=3D&quot;$base=
&quot; /&gt;</div><div class=3D"gmail_default">=C2=A0 &lt;meta name=3D&quot=
;description&quot; content=3D&quot;$Desc&quot; /&gt;</div><div class=3D"gma=
il_default">=C2=A0</div><div class=3D"gmail_default">=C2=A0 &lt;meta proper=
ty=3D&quot;og:site_name&quot; content=3D&quot;Tree Farm for Sale&quot;/&gt;=
</div><div class=3D"gmail_default">=C2=A0 =C2=A0 &lt;meta property=3D&quot;=
og:type&quot; content=3D&quot;article&quot;/&gt;</div><div class=3D"gmail_d=
efault">=C2=A0 &lt;meta property=3D&quot;og:image&quot; content=3D&quot;$FB=
image&quot;/&gt;</div><div class=3D"gmail_default">=C2=A0 &lt;meta property=
=3D&quot;og:title&quot; content=3D&quot;$Title&quot;/&gt;</div><div class=
=3D"gmail_default">=C2=A0 &lt;meta property=3D&quot;og:url&quot; content=3D=
&quot;$CurWebLink &quot;/&gt;</div><div class=3D"gmail_default">=C2=A0 &lt;=
link rel=3D&quot;shortcut icon&quot; href=3D&quot;/favicon.ico&quot; type=
=3D&quot;image/vnd.microsoft.<wbr>icon&quot; /&gt;</div><div class=3D"gmail=
_default">=C2=A0 &lt;link type=3D&quot;text/css&quot; href=3D&quot;/2col.cs=
s&quot; rel=3D&quot;stylesheet&quot; /&gt;</div><div class=3D"gmail_default=
">=C2=A0 &lt;link rel=3D&quot;canonical&quot; href=3D$CurWebLink /&gt;</div=
><div class=3D"gmail_default">=C2=A0 &lt;meta name=3D&quot;viewport&quot; c=
ontent=3D&quot;width=3Ddevice-width, initial-scale=3D1&quot; /&gt;</div><di=
v class=3D"gmail_default"><br></div><div class=3D"gmail_default"><br></div>=
<div class=3D"gmail_default">Ok.=C2=A0=C2=A0<br><br>The problem occurs with=
 the open graph FBimage tag.=C2=A0 If I don&#39;t define it in my header la=
ter then facebook uses no image at all when shared.=C2=A0 Otherwise it will=
 default to the first image on the page.</div><div class=3D"gmail_default">=
<br></div><div class=3D"gmail_default">How do I modify Header.inc so that i=
t doesn&#39;t put in the line=C2=A0</div><div class=3D"gmail_default"><br><=
/div><div class=3D"gmail_default"><span style=3D"color:rgb(34,34,34);font-f=
amily:&quot;times new roman&quot;,serif;font-size:small;font-style:normal;f=
ont-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;lette=
r-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white=
-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decor=
ation-style:initial;text-decoration-color:initial;float:none;display:inline=
"><span>=C2=A0</span>&lt;meta property=3D&quot;og:image&quot; content=3D&qu=
ot;$FBimage&quot;/&gt;</span><br></div><div class=3D"gmail_default"><span s=
tyle=3D"color:rgb(34,34,34);font-family:&quot;times new roman&quot;,serif;f=
ont-size:small;font-style:normal;font-variant-ligatures:normal;font-variant=
-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-in=
dent:0px;text-transform:none;white-space:normal;word-spacing:0px;background=
-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color=
:initial;float:none;display:inline"><br></span></div><div class=3D"gmail_de=
fault"><span style=3D"color:rgb(34,34,34);font-family:&quot;times new roman=
&quot;,serif;font-size:small;font-style:normal;font-variant-ligatures:norma=
l;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align=
:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:=
0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-de=
coration-color:initial;float:none;display:inline">if FBimage isn&#39;t defi=
ned in the calling template?</span></div><div class=3D"gmail_default"><br><=
/div></font></div></div></div><div class=3D"gmail_default" style=3D"font-fa=
mily:&quot;times new roman&quot;,serif"><br></div><div class=3D"gmail_defau=
lt" style=3D"font-family:&quot;times new roman&quot;,serif"><br></div><div>=
<div class=3D"m_-8834540766558369149gmail_signature"><div dir=3D"ltr"><div>=
<div dir=3D"ltr"><div><div dir=3D"ltr"><div>Regards</div><span class=3D"HOE=
nZb"><font color=3D"#888888"><div><br></div><div>Sherwood<br><br></div></fo=
nt></span></div></div></div></div></div></div></div>
</div>
</blockquote></div><br></div>

--94eb2c1a64a6c163bc0568bb1e41--


--===============5581367616686605396==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: inline

X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KdGVtcGxhdGVz
IG1haWxpbmcgbGlzdAp0ZW1wbGF0ZXNAbGlzdHMub3Vyc2hhY2suY29tCmh0dHBzOi8vbGlzdHMu
b3Vyc2hhY2suY29tL21haWxtYW4vbGlzdGluZm8vdGVtcGxhdGVzCg==

--===============5581367616686605396==--