Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

How to make dynamic result in META varriable in perl template toolkit

by romy_mathew (Beadle)
on Jan 08, 2013 at 17:28 UTC ( #1012294=perlquestion: print w/ replies, xml ) Need Help??
romy_mathew has asked for the wisdom of the Perl Monks concerning the following question:

Please suggest a solution

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:/ +/www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>[%template.title]</title> <meta name="generator" content="Ipad2 and iphone accesories" / +> <meta name="author" content="cloudsandcolors.com" />
[%Meta title = 'This is my heading' %]

The above code works without any problem but anytime I need to change the page title I need to manually correct the title head on page
I want to create a dynamic title for each page from a varriable. like

[%META title = '$varriable' -%]

The above code does not works, looking for a suggestion to work around this problem.

Comment on How to make dynamic result in META varriable in perl template toolkit
Select or Download Code
Re: How to make dynamic result in META varriable in perl template toolkit
by technojosh (Priest) on Jan 08, 2013 at 17:59 UTC
    You've only posted HTML. If this is really a problem of Perl inserting a variable title, consider below:
    use strict; use warnings; my $pageTitle = 'variable title text'; print qq[ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:/ + +/www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>$pageTitle</title> <meta name="generator" content="Ipad2 and iphone accesories" / +> <meta name="author" content="cloudsandcolors.com" /> ]; print qq[rest of properly formatted web page];
    The above will allow you to insert variable text in the title, if that is all you want.

    I suspect, however, you want something cooler, like dynamic update of <title> after page is already loaded. If I am wrong, my code above should help.

      Thanks for the post, my page is loading in template toolkit like
      [%content wrapper html + layout%]

      my header and footer were loading after all the content were created so bringing the variable to template was good and it started working.

      Thank for your time
Re: How to make dynamic result in META varriable in perl template toolkit
by 0day (Sexton) on Jan 08, 2013 at 19:17 UTC
    '$varriable' must be in double quotes ("$varriable").
Re: How to make dynamic result in META varriable in perl template toolkit
by CountZero (Bishop) on Jan 08, 2013 at 19:40 UTC
    The name of this game is called "Templates" and Perl is very good at it.

    Check out modules such as Template Toolkit, Mojo::Template, Mason or HTML::Template.

    There are many many more templating engines, the above are just a few randomly selected (although I personally like Template Toolkit very much).

    Update: Oops, sorry, only now I see your title. You are already using templates. (/me hides in a dark corner of the Monastery).

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics
Re: How to make dynamic result in META varriable in perl template toolkit
by theshz (Sexton) on Jan 09, 2013 at 19:11 UTC
    you can't put variable in [%META%], but why not use [% title %] instead of [% template.title %] in your template file, then you can define the $title anywhere you want.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1012294]
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2014-08-30 20:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (293 votes), past polls