Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID Sign In with Twitter
Support for Vanilla Forums Cloud product

In this Discussion

Follow Us


Can you use PHP in default.master.tpl?

edited March 2011 in Questions
I tried putting some PHP code into the default.master.tpl file of my template in an attempt to load the wordpress header.php, but it does not get parsed. When I view the source online, the PHP code is unchanged and appears to just be ignored. I also tried wrapping it in the {literal} tag to no avail. Can someone tell me if it's possible to embed PHP in this file?

Comments

  • LincolnLincoln Community Instigator Vanilla Staff
    edited March 2011
    Are you on vanillaforums.com or your own private install? If the latter, you could just use default.master.php instead if you don't mind eschewing Smarty.

    Sr Developer at Vanilla Forums [GitHub, Twitter]

  • I'm using a private install. default.master.php it outside the theme. Will it be overriden by upgrading Vanilla? Is there any documentation explaining how these files are used?
  • LincolnLincoln Community Instigator Vanilla Staff
    Just copy it into your theme under your views folder and hack away. :)

    Sr Developer at Vanilla Forums [GitHub, Twitter]

  • LincolnLincoln Community Instigator Vanilla Staff

    Sr Developer at Vanilla Forums [GitHub, Twitter]

  • @Lincoln, is to possible to add to quick guides instructions how to use compiled Smarty templates to replace Smarty tpl with pure PHP if you need this?
  • Sounds easy enough, I'll give it a go. BTW is there a function reference API for all the Vanilla PHP calls? It would make writing new methods so much simpler.
  • edited March 2011
    @tjforsythe
    What do you mean under "function reference API"?
    Vanilla uses MVC(Model-View-Controller paradigm) and objects.
    Plus event handlers as very useful helper approach.
    Read about all this in documentation on this site.

    Plus use good IDE (I prefer PhpStorm 2.0) and look into code (it is of quite high quality, many places are commented, arguments are also described according to PHP Doc)
  • I'm new to Vanilla, but looking at the code for some of the plug-ins for instance, they are making calls to methods I expect are part of the core classes i.e. Gdn::Session(). I am wondering if there is any documentation that describes these classes and methods. I could dig through the Vanilla core and eventually figure it out, but I'd prefer to start by reviewing a manual, if there is one available, so I know what tools are already available.
  • LincolnLincoln Community Instigator Vanilla Staff
    Some very unofficial code documentation: http://lincolnwebs.com/vanilla2doc/ It may move.

    Sr Developer at Vanilla Forums [GitHub, Twitter]

  • LincolnLincoln Community Instigator Vanilla Staff
    @tjforsythe Gdn::Session() refers to an instance of the class Session, which is in library/core/class.session.php. It's not a function.

    Sr Developer at Vanilla Forums [GitHub, Twitter]

  • LincolnLincoln Community Instigator Vanilla Staff
    @tester13 I have never used Smarty and have no plans to learn it.

    Sr Developer at Vanilla Forums [GitHub, Twitter]

  • Great, thanks for the link to the docs. Its exactly what I've been hunting for.
  • @Lincoln

    My understanding is that you can make exactly the same documentation using Doxygen and Vanilla source?

    As for Smarty - I asked not about how to use Smarty, but on how not to use it, in, for example, Mobile theme. I heard something about taking compiled PHP versions out from the Smarty cache.
  • LincolnLincoln Community Instigator Vanilla Staff
    @tester13 Yeah, that's how I made it... and?

    To use PHP templates, just call your files .php instead of .tpl. PHP template files override Smarty versions afaik.

    Sr Developer at Vanilla Forums [GitHub, Twitter]

  • Where is the default.master.tpl called from so I can change the call to default.master.php?
  • You do not need to change any call, as I understand, just remove tpl and place php instead.
  • LincolnLincoln Community Instigator Vanilla Staff
    Yeah, php always takes precedence over tpl. It's an either/or that Vanilla does automatically.

    Sr Developer at Vanilla Forums [GitHub, Twitter]

  • edited March 2011
    When I modify the default.master.php to include a header, menu and footer using lines such as <?php include('...//www.domain.com/path/include.php'); ?> (the dots as http obviously) they just seem to be thrown away. Any idea what I might be doing wrong?
  • LincolnLincoln Community Instigator Vanilla Staff
    edited March 2011
    Don't use includes with full paths, use echo $this->FetchView('viewname'); or include($this->FetchViewLocation('viewname'));

    If you must do a full path (i.e. the files are outside Vanilla) then you must use the relative or full system path to the file ('../../folder/file.php' or '/var/www/vhosts/folder/file.php'). You generally can't include over http.

    Sr Developer at Vanilla Forums [GitHub, Twitter]

  • edited March 2011
    I'm guessing Vanilla is doing some funky stuff with these includes. They work great if the file I am including is in the same folder as default.master.php (i.e. the views subfolder of my theme). It also works if the file is in another subfolder of the theme and I use ../subfolder/file.php. If I try to move the file to the theme root or any higher up the tree, it refuses to include it.

    I suppose I can get live with that, but it means I have to move my website wrappers into my Vanilla theme instead of where they belong ... in the website theme.

    Vanilla also strips out unclosed div tags from these includes, which is crummy. It's very common when writing wrappers to open a div in a header and then close it in a footer. Vanilla seems to be forcing me to move the wrapper portion into every file that uses the header and footer, which sort of defeats the purpose.
  • edited March 2011
    I must have had my folders crossed or perhaps it was my eyes. I thought the includes were relative to the views folders, but they are relative to the root folder of the forum, which means I CAN put my include files outside of the forum - great.

    Also since Vanilla strips the unclosed div tags, I can leave then in the header and footer where they are used throughout the rest of the site, and only need to add them the theme files, which is manageable.
  • If you still are interested in including PHP within your template you can use the {php} built-in function. smarty.net/docs/en/language.function.php.tpl

  • no with the default settings. not all smarty tags are enabled.

    Also if you are including php, you might as well copy default.master.php over and use that instead. Using php in a template language defeats the point of using a template language.

    grep is your friend.

Sign In or Register to comment.