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.
[RFC|Rejected] Template Vars in JS Files
[RFC|Rejected] Template Vars in JS Files
Last edited by MichaelC on Tue Feb 14, 2012 7:40 pm, edited 2 times in total.
Formerly known as Unknown Bliss
No unsolicited PMs please except for quotes.psoTFX wrote: I went with Olympus because as I said to the teams ... "It's been one hell of a hill to climb"
Re: [RFC] Template Vars in JS Files
I think you misunderstood purpose of RFC you linked to. It outputs file name, not content of file.
Formerly known as CyberAlien.
Free phpBB styles | Premium responsive XenForo styles | Iconify - modern open source replacement for glyph fonts
Free phpBB styles | Premium responsive XenForo styles | Iconify - modern open source replacement for glyph fonts
Re: [RFC] Template Vars in JS Files
Ah I only skim-read it.
First post updated.
First post updated.
Formerly known as Unknown Bliss
No unsolicited PMs please except for quotes.psoTFX wrote: I went with Olympus because as I said to the teams ... "It's been one hell of a hill to climb"
Re: [RFC] Template Vars in JS Files
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.
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.
Re: [RFC] Template Vars in JS Files
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.
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.
- callumacrae
- Former Team Member
- Posts: 1046
- Joined: Tue Apr 27, 2010 9:37 am
- Location: England
- Contact:
Re: [RFC] Template Vars in JS Files
I've been using data attributes and AJAX for stuff like this.
@UB: Search "script.php" - I've already made an RFC for this
@UB: Search "script.php" - I've already made an RFC for this
Re: [RFC] Template Vars in JS Files
I searched but that didn't come up. In that case I'll make this as rejected.callumacrae wrote:@UB: Search "script.php" - I've already made an RFC for this
Formerly known as Unknown Bliss
No unsolicited PMs please except for quotes.psoTFX wrote: I went with Olympus because as I said to the teams ... "It's been one hell of a hill to climb"