Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Can you use PHP in default.master.tpl?

13

Comments

  • peregrineperegrine MVP
    edited April 2014

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • chanhchanh OngETC.com - CMS Researcher ✭✭
    edited April 2014

    ok, I have been push off try not to learn yet another syntax but now look like I might have to force to look into it.

    I believe PHP is the most efficient template engine and no need for any add-on template engine but now since Vanilla is using it heavily and I choose to use Vanilla so I will have to force myself to learn about Smarty.

    Thanks

  • R_JR_J Ex-Fanboy Munich Admin

    I didn't know that you cannot use php directly and I would prefer it is still possible (though I understand why it is not).
    But, no, you do not have to learn something new: just put your (php) code in a function and call it from inside your template as all others (except me) have already advised to do.

  • chanhchanh OngETC.com - CMS Researcher ✭✭

    I know and I was trying to avoid it but now look like it is the only way or convert to php template like @vrijvlinder suggest.

    Thanks

  • hgtonighthgtonight ∞ · New Moderator

    @chanh said:
    I know and I was trying to avoid it but now look like it is the only way or convert to php template like vrijvlinder suggest.

    Thanks

    If you explain what you are trying to achieve, I am happy to outline the "Vanilla" way to do things. Just a vibe I am getting from my crystal ball tells me you should create a plugin and add a module somewhere.

    If you want to "convert" a .tpl file to a .php file, you could use the compiled version of the smarty template as a starting point. This isn't the best solution since you would have to translate the smarty plugins and variables, but it is another idea that hasn't been previously mentioned.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • chanhchanh OngETC.com - CMS Researcher ✭✭

    I have this autotranslate bar in PHP on top of all my sites where my sites can be seen in any of the language listed so I would like to just include it into my Vanilla site without doing too much work. That is my hope anyway but it does not seem possible with Vanilla.
    http://support.ongetc.com/

    Thanks

  • I have this autotranslate bar in PHP on top of all my sites where my sites can be seen in any of the language listed so I would like to just include it into my Vanilla site without doing too much work. That is my hope anyway but it does not seem possible with Vanilla.

    It is entirely possible. In smarty you can include vanilla assets, such as modules. You can also register new smarty functions, through the theme hooks.

    Views aren't there right for heavy logic in MVC, so this is more professional.

    However most auto translate, facilities are client based, using a SaaS. In your case google translate, who will translate the cached content from a scrape, or index.

    You really don't need php at all to include a bunch of links to Google translate. You may wish to do this ist is somehow make ti a bit easier. But it not dynamic content in itself. The dynamic bit is done by the SaaS.

    grep is your friend.

  • hgtonighthgtonight ∞ · New Moderator

    The "Vanilla" way would be to include a module to either the content asset or create a new asset and add the module to that. The module would just take the current URL and output a bunch of language links in the form of http://translate.google.com/translate?u={url_encoded_url}&hl=en&ie=UTF-8&sl=en&tl={language_code}.

    This could be done via plugin or theme-hook.

    If you are looking for translation plugins, you could check out the Translate This plugin: http://vanillaforums.org/addon/translatethis-plugin.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • chanhchanh OngETC.com - CMS Researcher ✭✭

    I am not sure I follow what you both suggest but I will look into your suggestion.
    Thank you both.

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    Yes what hgtonight suggests is that you use the translate this plugin. It does the same thing as the one you have. And you can also add more configurations to it and change the image for it. It is a pretty good addon. Also uses google translation engine.

  • chanhchanh OngETC.com - CMS Researcher ✭✭

    ok, I will check it out.
    Thanks

  • chanhchanh OngETC.com - CMS Researcher ✭✭

    translate this plugin only show in the dashboard but does not show on the front page where it need to show.
    Am I missing something?

  • vrijvlindervrijvlinder Papillon-Sauvage MVP
    edited April 2014

    It should show in the Panel . Do you have a link ? It could be that the jquery it is not working due to the tpl ...try this new version and see if it works. Other wise the best bet is to add the code to the tpl like this in your tpl where you want it to show exactly like below.

        <!-- Begin TranslateThis Button -->
    
        <div id="translate-this"><a style="width:180px;height:18px;display:block;" class="translate-this-button" href="http://www.translatecompany.com/translate-this/">Translate This</a></div>
    
     {literal}   <script type="text/javascript" src="http://x.translateth.is/translate-this.js"></script>
        <script type="text/javascript">
        TranslateThis();
        </script>{/literal}
    
        <!-- End TranslateThis Button -->
    
  • vrijvlindervrijvlinder Papillon-Sauvage MVP
    edited April 2014

    here is the same plugin but as a module maybe it works better...but you will have to sort the modules if you want it to appear elsewhere in the panel. If you want it in the Menu area change the asset target in the module to Menu or Head Or Content ...

  • chanhchanh OngETC.com - CMS Researcher ✭✭

    where would I put this? in the plugin folder or somewhere else?

    Thanks

  • I think it would be odd using a different facility when he can implement what he wants, with a module.

    grep is your friend.

  • chanhchanh OngETC.com - CMS Researcher ✭✭

    What is a module?
    How would I implement my PHP code in a module?
    Thanks

  • vrijvlindervrijvlinder Papillon-Sauvage MVP
    edited April 2014

    @chanh said:
    where would I put this? in the plugin folder or somewhere else?

    Thanks

    The one in the zip is a plugin and it goes in the plugins folder, the code I posted goes inside your tpl. Choose the one that works for you.

    The plugin I made , in the zip, is a module . Look at it and make your own if you don't like how this plugin works... Just clone it. and replace the code with yours..

    Sometimes I wonder about you chanh... ;)

    What is a module? How would I implement my PHP code in a module?

    A module is just another name for a pocket or container or widget. All the parts in the layout are made of assets and modules which are also assets.

    A module is a way of adding content instead of adding the code in the master you use a module. The new discussion button is a module. The bookmarks box is a module.

  • chanhchanh OngETC.com - CMS Researcher ✭✭

    I had figure out where to put the module zip file that you provided while waiting for a respond.

    Just a few feedback on this plugin/module.

    . The translation only translate on certain text but not all content of the post.
    . When you select a language, it get stuck on that language and wouldn't go back to the default even if I click to choose the default.

    Now I see the different between the module and plugin. I also discover there are so many way of doing thing and the terminology is a bit overwhelming. Plus the document seem to still referencing the old structure in 2.0 rather than in 2.1 and it get confusing at time.

    I thank you for all the help.

  • vrijvlindervrijvlinder Papillon-Sauvage MVP
    edited April 2014

    The translation only translate on certain text but not all content of the post

    that is a known bug with translators like this, usually it happens if it detects that the language is already in use. Also sometimes it will redirect to the google translate page.

    I have this button on several installs and it is not very consistent. On one install it will translate the whole page, in others only the forum parts not the titles. I am not sure why this is. Other than it can't find the translation for it.

    Here is example of one that works on all text

    http://mydatabass.com/Forum/

    and the same button on another forum that for some reason does not change the titles

    http://freeplanet3.com/Forum/

    And my forum which redirects to the google translate page something I don't really want

    http://www.vrijvlinder.com/forum/

    I don't know why they all work different. I did write the company but got no answer.
    I do know that it uses cookies so that may be an issue.

    You can try to add the code in the tpl, but I doubt that will make a difference. I think this has to do with the google engine and not with this button. Also the browser my have something to do not sure really.

    Here is the link to the company that made it so you can check it out. http://translateth.is

Sign In or Register to comment.