[RFC|Rejected] Template Vars in JS Files

These RFCs were either rejected or have been replaced by an alternative proposal. They will not be included in phpBB.
Post Reply
User avatar
MichaelC
Development Team
Development Team
Posts: 889
Joined: Thu Jan 28, 2010 6:29 pm

[RFC|Rejected] Template Vars in JS Files

Post by MichaelC »

At the moment to include template vars in javascript you need to have it actually on the main HTML template file, not included files. It makes sense to be able to use template vars in javascript files.

However, I'm not sure how this can be done due to the nature of including JS files.
Last edited by MichaelC on Tue Feb 14, 2012 7:40 pm, edited 2 times in total.
Formerly known as Unknown Bliss
psoTFX wrote: I went with Olympus because as I said to the teams ... "It's been one hell of a hill to climb"
No unsolicited PMs please except for quotes.

User avatar
Arty
Former Team Member
Posts: 985
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars
Contact:

Re: [RFC] Template Vars in JS Files

Post by Arty »

I think you misunderstood purpose of RFC you linked to. It outputs file name, not content of file.

User avatar
MichaelC
Development Team
Development Team
Posts: 889
Joined: Thu Jan 28, 2010 6:29 pm

Re: [RFC] Template Vars in JS Files

Post by MichaelC »

Ah I only skim-read it.

First post updated.
Formerly known as Unknown Bliss
psoTFX wrote: I went with Olympus because as I said to the teams ... "It's been one hell of a hill to climb"
No unsolicited PMs please except for quotes.

User avatar
brunoais
Registered User
Posts: 964
Joined: Fri Dec 18, 2009 3:55 pm

Re: [RFC] Template Vars in JS Files

Post by brunoais »

Not quite sure what you are asking.
Anyway, do you mean being able to include other .js files in the same file in order to create a final minimized .js file?
I already had that idea. Dunno about implementing it or not. I didn't make an RFC about that yet because I don't have Ideas well thought yet.

If you mean including template vars that imply dynamically generated .js files that originate a .php file that needs to be executed every single time.
I really really strongly disagree.

igorw
Registered User
Posts: 500
Joined: Thu Jan 04, 2007 11:47 pm

Re: [RFC] Template Vars in JS Files

Post by igorw »

This is intentional, adding templates into JS cause a lot of problems.

If we want to do that, we need to compile the JavaScript. Since these variables are not constants, we'd have to compile it on the fly, so basically generate the JS every time. Which is terrible, JS must be static and cacheable. Assetic could allow us to do it in theory.

The way you get things out of the HTML is by using data attributes. For almost all cases this works really well, because usually we're interacting with some DOM element anyway. So then we can just get the additional data associated with that element.

I totally see that there are certain use cases where this is not ideal, but I still think it's better to keep things separate, because it separates HTML and JS cleanly.

I think it's a bad idea.

User avatar
callumacrae
Former Team Member
Posts: 1046
Joined: Tue Apr 27, 2010 9:37 am
Location: England
Contact:

Re: [RFC] Template Vars in JS Files

Post by callumacrae »

I've been using data attributes and AJAX for stuff like this.

@UB: Search "script.php" - I've already made an RFC for this ;-)
Made by developers, for developers!
My blog

User avatar
MichaelC
Development Team
Development Team
Posts: 889
Joined: Thu Jan 28, 2010 6:29 pm

Re: [RFC] Template Vars in JS Files

Post by MichaelC »

callumacrae wrote:@UB: Search "script.php" - I've already made an RFC for this ;-)
I searched but that didn't come up. In that case I'll make this as rejected.
Formerly known as Unknown Bliss
psoTFX wrote: I went with Olympus because as I said to the teams ... "It's been one hell of a hill to climb"
No unsolicited PMs please except for quotes.

Post Reply