what is the best way to load an theird part library?

Ajaxboy

Active member
what is the best way to load a third party library in the head of the page?

I can see someone responding saying by adding it to a template.

But I am looking for a dynamic way done through php.

eg: somethign like Xenforo_Template_html::addToHead(); (that doesn't exist, but it is an example)

Just trying to find the simplest within xenforo


ps: feel free to fix the spelling on the title :), I wasn't awake apparently
 
The templates are templates because they are intended to be edited in order to achieve this kind of modification. If the templates were intended to remain strictly unchanged, we could have left them hard-coded in PHP and not expended vast amounts of effort providing a templating system.

Therefore, the answer is, for now at least, add the library to the appropriate template.
 
I dislike the response, but rightfully said. In no way it would be hard-coded, that is really a strong word. "strictly unchanged" it is also a strong word. Very strong. I have a class dynamically return the relative path of a scrip tag. I use templates myself that loop through the head to "deposit" any residual gathered toward the head tag through a single variable. In no way I don't believe this is considered "hard-coded" it is all the opposite. Sounds to me you are using strong words to avoid dealing with it. Which is very understandable. Though I need this, people ask for things because they need them.

I am not very experienced with integrations (ehh a little bit), but I am experienced buildings shopping carts, frameworks, and applications in general.

Not many would need this kind of power, having already everything that the system does. I am sure some of things I am trying to load the system can already do, but I am experimenting and reaching the flexibility of xenforo. I am a hardcore developer what are you gonna do?... he .. and I am trying to load my favorite tools into xenforo to see what kind of fancy stuff I can do on it you can say. I built a js ajax framework that you can relate with jquery but not exactly, but you should get the idea from there (is what I am trying to load). Using templates or even an addon to reach the head tag (with all the respect) is ridiculous, doesn't mean I wouldn't do it, but it kind alienates (some) developers you should know that. I rather think this is a very generic tool, for such purpose.

...
From all of the said above, just the bold part above is what I need without having to actually create or edit a template or create an addon. Thank You.


Oh btw, why do I have so much trouble editing a template you ask?... I don't.... I am thinking distribution the whole time. I don't want people to deal extra template modifications and the like when an addon is distributed, etc. Should be straight forward.
1
 
If you want to include a javascript library in the head from within another template, that is very straightforward.

Simply use the <xen:require ... /> tag, like this:
HTML:
<xen:require js="path/to/javascript.js" />
This may be used as frequently as you like, from any template in your add-on.
 
This is the part you don't understand.. the JavaScript is actually generated by a php class. I can't manually take and put it there. Well technically I can, but now that is what can be considered hard-coded (kind of exactly what I am trying to avoid).
 
basically all you need is a template like this

HTML:
<xen:if is="{$head_var}">
<xen:foreach loop="$head_var" value="$head">
{$head}
</xen:foreach>
</xen:if>
and .. a php function that stacks input into an array, that should do it.
 
I mean there's already the part you requested in the template.


And mike wrote
I just put together a quick recursive merging function that will allow this to work in the next release.
So it SHOULD be already available.
 
I mean there's already the part you requested in the template.


And mike wrote

So it SHOULD be already available.
Nope it didn't work,.

I did see the PAGE_CONTAINER template on there though. I am trying to avoid editing templates that are simply unnecessary to edit.
 
The functionality already exists on line 18 of the PAGE_CONTAINER template:
HTML:
<xen:if is="{$head}"><xen:foreach loop="$head" value="$headElement">{xen:raw $headElement}</xen:foreach></xen:if>
 
on this note..

Would it be OK practice to create a new template called lets say: "custom_includes" entering in all the necessary addon libraries I require using <xen:include template="path/to/jscript.js" /> for as many libraries as I need and then in the page container template only need to make one edit: <xen:include template="custom_includes" /> ?
 
on this note..

Would it be OK practice to create a new template called lets say: "custom_includes" entering in all the necessary addon libraries I require using <xen:include template="path/to/jscript.js" /> for as many libraries as I need and then in the page container template only need to make one edit: <xen:include template="custom_includes" /> ?
that's what i'm doing for my add-ons.

The functionality already exists on line 18 of the PAGE_CONTAINER template:
HTML:
<xen:if is="{$head}"><xen:foreach loop="$head" value="$headElement">{xen:raw $headElement}</xen:foreach></xen:if>
i wrote this already in post 7:P

BUT how can we add own code to this?

I know only the way with <xen:container.... which can only be used in templates.
How can i add own elements from php code, without editing templates?
 
front_controller_pre_view will work. But I think container_public_params is more appropriate.
This works for me:
Code:
$containerParams['head']['customParam'] = '<!-- FooBar -->';

Just choose a parameter name that's not used in any template. A head parameter set in a template always takes precedence over a parameter by the same name defined anywhere else, in code.
 
In case anybody ever needs this, this worked: (although it was not the solution I was looking for, but it will do :) )

(For some reason none of the above example worked)

first add an event: template_hook

PHP:
    public static  function hook_me_up_baby($name , $contents ,array $params,XenForo_Template_Abstract $template)
    {
        if($name=='page_container_head') {

            return $contents .= "\t<!--Foo-->";
        }

    }

I wanted to do it without requirement of a template.. just a simple built in helper.. etc.. but seems like it works out


Why a helper would of been better you ask?..... Well just see how long it took, at least 2 to 4 days.. with a helper it would of have taken just 5 min max... that is why I like to keep things simple.. :D. No need to create a whole house, just to spend one night in it.. does that make sense :oops:.
 
Top Bottom