{$category->id|escape:'htmlall':'UTF-8'}
this smarty code is for get id number on category.tpl
we have lot of category id's example 2,6,8,10 etc etc and in my folder lots of files names example 2minimum.txt, 6minimum.txt, 8minimum.txt, 10minimum.txt etc etc
i want to use include file when current category id page with category id number txt file.
{include file='folder/2minimum.txt'} <=- this will work perfect when i put file name but i want to use like this
{include file='folder/{$category->id|escape:'htmlall':'UTF-8'}minimum.txt'}
but it's give error
experts need you help to solve this
You should use smarty cat to concatenate variable to your file name. In your example it should look something like:
{include file='folder/'|cat:{$category->id|escape:'htmlall':'UTF-8'}|cat:'minimum.txt'}
Link to smarty documentation
Hope it helps, have a nice day!
{include file='folder/'|cat:$category.id|cat:'minimum.txt'}
In smarty {} means {this is smarty}.
But you wrote {this is smarty{what's this?}this is smarty}.
It was a syntax error.
And I'm not sure, but I think $category->id is php code style. You could find $category.id is smarty code style in Prestashop template files.
And $category.id returns number. I don't think it needs escape.
Related
I have been trying to modify some of part of HTML but I am stuck at this moment.
I am looking for a word, the file that includes the word that I want to modify or delete on HTML exactly.
please check following html code :
<input class="wSearchField no-filter" type="text"
data-class="no-filter: !#KEY_FEATURE.filter"
data-attr="placeholder: #KEY_LNG.Search;aria-label:#KEY_LNG.Search" data-value="KEY_SEARCH_TERM"
data-focus="#focusin_searchbox(true)"
data-blur="$sc.handleFocusOut('focusin_searchbox')|timeout:200"
data-keyup="$mc.newSearch(node.value, event.keyCode),$sc.handleKey(event)|debounce:150"
tabindex="7" placeholder="-Search-" aria-label="-Search-">
I want to modify right here placeholder="-Search-" (at the last line) as placeholder="-"
Which file does have the word "Search"? I am not able to find it out of many files.
Thanks have a great day
Do you mean this?
document.getElementsByTagName("input")[0].setAttribute("placeholder", "-");
https://codepen.io/anon/pen/wYVgmm
you can set by javascript
document.getElementsByClassName("wSearchField").placeholder = "Type name here..";
or you can try using jquery
$('.wSearchField').attr("placeholder", "Type your answer here");
Okay, i found the file related to that text. it's included on javascript file as a part of code.
Thank you guys
I need to include a js file in my views.
But in this js file i need to interpret somes PHP variable.
Actually i do this :
#section('javascript')
<script>
alert("{{{test}}}");
</script>
#stop
But i REALLY need to do this :
#section('javascript')
{!! Html::script('js/test.js') !!}
#stop
test.js :
alert("{{{test}}}");
I need to declare a lot o variable. So my JS file will be very huge. And i don't want to show this directly in the source code.
How can i do ?
Thank you !
You can only pass the variable to the javascript like so:
#section('javascript')
<script>
var test = {{{$test}}};
</script>
#stop
then in your javascript file included at the bottom you can use it:
alert(test);
Let me just mention that this is not a great way of handling the passing variables from php to javascript.
When I need to do something like this, I usually create a meta tag on the page which would contain the alert information.
<meta name="someAlertValue" content="{{{ $test }}}" />
Then you can very easily grab that via jQuery.
var alert_text = $('meta[name=someAlertValue]').attr('content');
I find this approach to be much cleaner and maintainable than trying to drop php variables directly into your javascript.
I had the same problem, and wanted to have a stand alone js which will have bunch of variables taken from config() or even from database, multi-language, and will be configurable, or even will work with query parameters.
Maybe it's a hard way, but i've created a route:
Route::get('/js-modules/test.js',function(){ return view('js-modules.test');})->name('my_js);
So in the view resources/views/js-modules/test.blade.php you can put your js code together with your PHP stuff.
Or you can route it to a controller and have even more background work. it looks a bit slow (in the browser) on the first run , but second request it'll be cashed and retrieved as the regular js file
And now you can link it to any of your pages with
<script src="{{route('my_js')}}"></script>
How can I get Vim to correctly syntax-highlight in a situation such as this (used, e.g. with Knockout templates):
<script type="text/html" id="my-template">
<!-- This should be rendered as HTML -->
<div>Some template</div>
</script>
<script>
//This should be rendered as Javascript
var x = function() { return 3; }
</script>
The solution given here involves editing Vim's internal syntax file, which seems wrong, and it specifically looks for "text/javascript" which is no longer needed in <script> tags.
I assume the solution is some sort of syntax plugin I can keep in my .vim directory but am not familiar enough with Vim's syntax internals to figure it out.
(Note that this question and answer don't apply as I'm not using Ruby on Rails.)
Maybe this will help you: https://coderwall.com/p/vgk5-q/make-vim-play-nice-with-html-templates-inside-script-tags.
In case the link above is broken one day - put the following code into ~/.vim/after/syntax/html.vim:
unlet b:current_syntax
syn include #HTML $VIMRUNTIME/syntax/html.vim
syn region htmlTemplate start=+<script [^>]*type *=[^>]*text/template[^>]*>+
\ end=+</script>+me=s-1 keepend
\ contains=#HTML,htmlScriptTag,#htmlPreproc
Somebody should write a plugin for that! ;)
First copy the vim's internal html syntax file to $HOME/.vim/syntax/html.vim so that you only change the behaviour for yourself not globally.
Then find the line starting syn region javaScript and replace it with two lines
syn region script_notype start=+<script>+ keepend end=+</script>+me=s-1 contains=#htmlJavaScript,htmlCssStyleComment,htmlScriptTag,#htmlPreproc
syn region script_jstype start=+<script[^>]*type="text/javascript"[^>]*>+ keepend end=+</script>+me=s-1 contains=#htmlJavaScript,htmlCssStyleComment,htmlScriptTag,#htmlPreproc
The first line is for plain <script> tab, the second for <script type="text/javascript">.
However, this won't cover a situation with <script> tag without type attribute having other attributes. This case should get javascript syntax but won't. I guess this is a minor problem.
can anybody tell me what am I doing wrong?
I want to retrieve all my alfresco sites with this code (this should work):
model.sites = siteService.listSites(null, null, 0); // return type= List<Site>
And now i want to retrieve this list model.sites in my HTML freemarker template like this:
<body> ${sites} </body>
How can I view this sites list. I know i am getting it wrong in my ftl, but can't find a solution how to retrieve it.
You'll need to loop over the sites in your freemarker. Assuming you wanted a list of the site names, with commas between them, then your freemarker would instead want to look something like:
<body>
<#list sites as site>
${site.shortName}<#if site_has_next>,</#if>
</#list>
</body>
I'm trying in a Rails app to render some json data through a mustache template.
My starting point was this railscast: http://railscasts.com/episodes/295-sharing-mustache-templates
In the cast Rayn does something like
$('#target').append Mustache.to_html($('#project_template').html(), json-data)
Having in the html a div with id="project_template" that contains the template
<script type="text/html" id="project_template">
...
</script>
However, I'd like to be able to store the mustache template into a file (let's say in app/views/projects/project.mustache) and load it directly in my js.
Something like
$('#target').append Mustache.xxxxx(MUSTACHE_FILE, json-data)
I have looked around but I cannot find anything that works or any suggestion. Is this possible to achieve?
Thanks.
You can't access server-side file in javascript directly, but you can use an alternative way to store template on the server side.
You can store the template in app/views/projects/project.mustache for example.
In your project.mustache, you can write:
<script type="text/html" id="project_template">
...
</script>
In your view, you can use:
<%= render :file => 'projects/project.mustache' %>
And use javascript as same as before.
$('#target').append(Mustache.to_html($('#project_template').html(), json-data));
I think it isn't perfect, but it should work :)