On 8/02/2013, at 9:54 AM, Uncle Cheese <
aaronc...@gmail.com> wrote:
> Yeah, I agree. The only reason I suggested it was because SS seems to
> embrace constants so much. I'm looking at you, Core.php!!
>
> Glad to see they're on their way out, though.
>
>
>
> On Thursday, February 7, 2013 2:58:06 AM UTC-5, Ingo Schommer wrote:
>>
>> Constants should really be converted to object state
>> somewhere early in the bootstrap/config process, the fact that we
>> don't do this enough is a weakness in the API.
>> The "MY_MODULE" example seems most useful in templates,
>> and that's going to be covered by AJShort's work on the module API
>> during GSOC (not merged into core yet). Constants are global state,
>> we shouldn't encourage its use more by making them available in templates.
>>
>> ---
>> Ingo Schommer | Senior Developer
>> SilverStripe (
http://silverstripe.com)
>> Skype: chillu23
>>
>> On 7/02/2013, at 5:59 AM, Uncle Cheese <
aaronc...@gmail.com <javascript:>>
>> wrote:
>>
>> I've gotten in the habit, as several other contributors have, of defining
>> a module directory in the _config.php like so:
>>
>> *define('MY_MODULE_DIR', basename(dirname(__FILE__)));*
>>
>> This affords the user the ability to install the module anywhere.
>>
>> *Requirements::javascript(MY_MODULE_DIR.'/javascript/my_js.);*
>>
>> This works great, except when I have to create paths to the module in SS
>> templates, e.g. inline images.
>>
>> *<img src="MY_MODULE_DIR/images/myimage.png">* <--- Doesn't work
>>
>> Neither does this:
>>
>> *<% require javascript(MY_MODULE_DIR/javascript/my_js.js) %>*
>> *
>> *
>>
>> One option is to push the variable into the template via a controller
>> function, but that seems like unnecessary boilerplate to me. What might be
>> the implications of allowing SS templates to parse constants?
>>
>>
>>
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "SilverStripe Core Development" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to
silverstripe-d...@googlegroups.com <javascript:>.
>> To post to this group, send email to
silverst...@googlegroups.com<javascript:>
>> .
In the mean time, you can use something like:
class ConstantTemplateGlobalProvider implements TemplateGlobalProvider {
public static function get_template_global_variables() {
return ['Constant'];
}
public static function Constant($name, $extra = '') {
return constant($name) . $extra;
}
}
Then you can do things like <% require javascript($Constant('MY_MODULE_DIR', '/javascript/my_js.js')) %>
---
Simon Welsh
Admin of
http://simon.geek.nz/