How do I declare a freemarker macro/function to be used within a few ajax views? - freemarker

I currently have a <#macro format_phone phone> within my code, and a few different pages use it. How could I make this function be available to many pages? ie. globally. Currently it's copied and pasted, breaking the DRY principle.

You can put it in a macros.ftl file, <#import "macros.ftl" as m>, and then <#m.format_phone phone>

Related

Unable to make Smarty tag meaning

I have below code in smarty template. I am unable to interpret what paging does. calc, total, current, per_page, url are variable but what is paging
{paging calc=$pInfo.calc total=$dealers|#count current=$pInfo.current per_page=$config.dealers_per_page url=$search_results_url}
{paging} seems to be a custom Smarty plugin.
as #Iko mentioned, {paging} is likely a smarty plugin
Check your smarty plugins folder for a file named 'functions.paging.php' - you should be able to find the php code that processes those parameters. If you're lucky that code might have links to documentation or the publisher if created by a third party.
http://www.smarty.net/docs/en/plugins.naming.conventions.tpl

Laravel - Custom Plugin with Template

I have these "containers" which each holds one major section of my code. A page is therefore built up of a few containers, and they all look and behave the same. In my route directory, I have the following architecture
app
/containers
/Main
MainContainer.php
ContainerName1.php
ContainerName2.php
...
/Side
SideContainer.php
ContainerName3.php
ContainerName4.php
...
/Aux
AuxContainer.php
ContainerName5.php
ContainerName6.php
...
BaseContainer.php
So MainContainer.php, SideContainer.php, and AuxContainer.php all extend BaseContainer.php, and each ContainerName#.php extends the appropriate container. I currently have all the HTML/Views done within these containers themselves. But I wanted to move all HTML/Views to a template.
Should I have the templates in the /views folder, or should I keep it in this /containers folder? The reason why I may want to keep it in the /containers folder is because there will be a base.blade.php, and main.blade.php (and side/aux), and then one per ContainerName#. So it may stay cleaner if they are all there?? If I can do this, how do I call it?
I think this is partially a matter of opinion, but I'll toss my opinion in here and I suppose people can downvote me if they disagree.
I think it's better to keep all your views in /views, mostly because that's the appropriate and expected place for them. If anyone other than you were to maintain this project, they'd look for views in /views, and I think they'd be throughly confused if they were stored in some containers.
Here's what my view structure looks like in my project:
views
/layouts
main.blade.php
/includes
analytics.blade.php
navbar.blade.php
flair.blade.php
...
/account
main.blade.php
public-listing.blade.php
public-profile.blade.php
...
/game
listing.blade.php
settings.blade.php
...
about.blade.php
contact.blade.php
help.blade.php
I have my main templates in layouts (which is essentially my stock bootstrap code), I have little bits that I'll include in includes (things that will never be webpages on their own, but make other web pages work), and the rest goes in a sub folder depending on the controller. From each of my "full" views, the top line is #extends('layouts.main') and that makes sure it inherits the correct layout (if there was more than one, although there isn't in my example).
I think something like this could easily work for your project, and would go a long way in making it easier for you and anyone else to maintain.

Using PHP functions in phpBB template files

I'm trying to manipulate some code inside of a phpBB template file. Essentially, the forum descriptions contain some markup that needs to be converted before being displayed.
I am able to display the description using code similar to the following:
<!-- ELSEIF forumrow.FORUM_DESC -->
<li class="row"><span>{forumrow.FORUM_DESC}</span></li>
<!-- ENDIF -->
However, how can I wrap the forumrow.FORUM_DESC inside a html_entity_decode() function or something similar? I've tried moving the {forumrow.FORUM_DESC} into blocks, but the variables are different.
Probably not the best way to solve this, but I was able to modify the code to look something like this:
<!-- PHP -->echo html_entity_decode($_forumrow_val['FORUM_DESC']);<!-- ENDPHP -->
I was able to determine the values of the variables with a backtrace:
var_dump(debug_backtrace());
Again, may not be the best solution, but hopefully it helps someone else that hits this snag.

Codeigniter extend helper but want to call old helper

I am developing an Application in Bonfire.
They have extended the form helper.
Is there a way to call the original form helper from Codigniter without removing the extended one from Bonfire?
"Helpers" are just files with PHP functions in them. They aren't actually "extended", Codeigniter loads it's default helpers after loading yours, and checks if you "overwrote" a function like so:
if ( ! function_exists('form_open'))
{
function form_open() {/* default code */}
}
So unfortunately, no - there's no way to call the original function if you already declared your own.
HOWEVER: It appears that Bonfire does the exact same thing, checking with function_exists, so if you want to - you should be able to load your own form helper before it, but you still cannot simply load the original one without hacking Bonfire and removing the functions (which could have terrible side effects).
Faced the same prob, user742736's comment is the only answer that solved the prob.
Explained in detail, may be this can help some one
You can create your own helper function with out the divs surrounding the drop down here
bonfire/application/helpers/MY_form_helper.php
make a copy of the function form_dropdown, name it like form_dropdown_plain
modify the last few lines of the function to output with out divs
call form_dropdown_plain instead of form_dropdown

How to use include function in another custom function?

I am using Smarty 3.1.8
I want to include a tpl file only one time on page even if tpl file called more times.I dont know that I can do the that with Smarty without write a new custom function.So I think to write a new custom include function for this.
Can I use include function of smarty in the custom include function ?
I want to use smarty include function in my the custom include function for compile given template.
How am I do this ?
I want to use as follow :
{include_js file="script.users.tpl"}
Are you using PHP? If, so try this:
Even though it's in Smarty, use the php include_once("/dir/filename"); function.
using smarty_bc or smarty2:
{some_smarty.tpl}
<html>
<p>ex paragraph one</p>
<p>ex paragraph two</p>
{php} include_once("script.users.tpl"); {/php}
</html>
This way you can rely on having PHP monitor that the file is only being inserted once.

Resources