Possible to run Blade on variable? - laravel-4

Is it possible to run the Blade engine on an variable?
Let's say i have variable called "$render" which equals to "#if($something == $something) $(".hello").show(); #endif"
And i would then run something like "View::make($render);".
I am trying to add this functionality to a package that Minifies JS files.

From what I can find in the docs and from my experience, you can't.
I think what you are looking for is #include('some_file'). Whic means you will ALWAYS run the #if statement.

Related

Is Laravel blade '#include()' case-sensitive?

I'm getting a "blade not found shop.cart.favorites" error when running in Docker on Ubuntu. (Therefore: "case-sensitive file system.")
I suspect that the culprit is case-sensitivity. The path to the blade file is:
resources/views/Shop/Cart/favorites.blade.php
^ ^
Did I guess correctly?
You have made a little mistake bro...
Change in your Controller/Function where you defined the View .Like this.....
return View('Shop.Cart.favorites');
It will work.. Check it out..
Thank you.
In the process of rendering a View, the view() method in Laravel checks to see if a Blade template file exists at the path provided using the PHP built-in method file_exists().
Although the docs don't mention it at all, it has long been observed that this function can be case sensitive (typically on *nix-based filesystems, though not on Windows). But since you don't necessarily know where your code will be run (e.g. if you are creating a package), best practice for cross-platform compatibility is to use only lowercase filenames for Blade template files.
Okay, thanks folks. Indeed, that's the [ANSWER] I was expecting: the underlying filesystem is case-sensitive, and therefore so is PHP (file_exists() et al ...), and therefore so is Laravel. Blade file and folder names are case-sensitive.
Now ... here's a follow-on question: is there a handy-dandy plugin for Laravel that might enable me to "skate around" this issue? (Yeah, I think I know what that answer will be, too. But it doesn't hurt to ask ...)

smarty - copy variable and add it to another

I am using smarty and have a fairly simple question that I just don't know the correct terminology to find the answer for.
I am trying to make so that my meta description is a combination of two variables.
{$product.descr|cat:" Learn More about:"|cat:$product.fulldescr}
The above code works, but I need to use the "|replace" function on the second variable but not the first one.
So, I think I would want something like this:
{assign var='fulldescr-changed' value=$product.fulldescr|replace 'x':'y'}
{$product.descr|cat:" Learn More about:"|cat:$fulldescr-changed}"
This does not work though and I am not sure what I am doing wrong. Any thoughts would be appreciated.
You forgot a colon after replace. Also I would not use a hyphen in the name of the variable:
{assign var='fulldescr_changed' value=$product.fulldescr|replace:'x':'y'}

loading macro files in a directory, transparently

I am looking for a way to separate the repetitive html codes from web pages, and for this I am planning to use the macro functionality. The problem here is for every macro I need to put this macro in a file, or put some of them in a file and include this in the template file.
What I need is to include once just the directory name something like
<#import "/tags/widgetDirectory" as widgets />
here the /tags/widgetDirectory is a directory , and every files here can be seen as a macro defined.
when I need to insert a code part from a file from this directory lets say slide.ftl I will just use
<#widgets.slider />
the system will check for slider.ftl in the /tags/widgetDirectory directory . here the slider.ftl can have <#macro> as first and as last line , or these can transparently added and system can load it as a macro
this will easy my designer work.
Maybe there is better way for doing this kind of widgets/components based web design ?
best regards,
This feature (importing directories) is something that's planned for FM actually... but it won't happen anytime soon. But I guess it can be solved fairly well with a hack right now. Instead of #import, use your own TemplateMethodModelEx, that you could use like <#assign widgets = importDirectory('/tags/widgetDirectory') >. This will return a TemplateHashModel that's also implemented by you and is bound to the directory path. When an item of that hash is get, it uses Environment.getCurrentEnvironment().include. The included file is expected to create a macro with name __main or something. So then you get that variable with Environment.getCurrentNamespace().get("__main") and return it as the result of the hash lookup. Of course this hash should also maintain a cache, so that if the same item is get twice, it wont include the template for the second time, just return the macro extracted earlier. This can be developer further, so that if the include file didn't define __main, then it's supposed that it prints directly to the output, and so it will be included again, when the "tag" is called again.

ISN AutoIT Studio - creating new form

I created .isf form file in ISN studio. In my main.au3 file I have included this form (#include "Forms\main.isf"). But when i hit run nothing happens. Do I have to add somenthing in my main.au3? (I'm pretty new with AutoIT)
Also when I look into code which form generates there is:
$btn1 = GUICtrlCreateButton("Button",170,70,100,30,-1,-1)
GUICtrlSetOnEvent(-1,"onBtn1Click")
shloudn't be there $btn1 instead of -1 in the second line?
Thanks :)
You need to make it a user defined function (UDF). That won't work because a UDF needs to be a .au3 file. I'm not familiar with ISN studio, however to include a UDF you need to do this.
#include "C:\path\myfunctions.au3"
Also if the UDF is in the same location as the script you can just use the relative path like this.
#include "myfunctions.au3"
Here is are some example UDF's.
http://www.autoitscript.com/wiki/User_Defined_Functions
You have done nothing wrong; just forgot something.
It's correct to include the .isf file in your script. So the GUI is already present, just hidden! You only need to show it using: GuiSetState(#SW_SHOW, $HANDLE_OF_YOUR_GUI).
Then you should see your GUI! As an example see the "Testproject" in ISN AutoIt Studio.

Using Apache and mod_ext_filter, need to dynamically replace values of static file based off of query string

I've got a situation where I need to alter the contents of a cached file based off of one of the query string arguments passed in. I'd love to use sed to do a simple regular expression replacement of a value based off of said argument but I can't figure that one out. I could use a ruby script to do the replacement for me but can't seem to access the query string for the request within the script. The documents for mod_ext_filter say:
In addition to the standard CGI environment variables, DOCUMENT_URI, DOCUMENT_PATH_INFO, and QUERY_STRING_UNESCAPED will also be set for the program.
Um yeah, can't seem to access those.
Has anybody any experience with this or does anybody have a better solution?
Doh! Looks like I simply need to access the ENV variable within ruby. Pretty dumb of me.
Using PHP scripting language server function we can able to get the query string values.
echo $_SERVER['REQUEST_URI'];
And pass the URL arguments as a variable to the file and make it dynamic.
Refer : PHP.net

Resources