Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Putting smarty code in a html block in a javascript file

 
Post new topic   Reply to topic    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
aidendoyle1981
Smarty Rookie


Joined: 11 Jan 2016
Posts: 9

PostPosted: Sun Aug 21, 2016 10:26 pm    Post subject: Putting smarty code in a html block in a javascript file Reply with quote

I am using a javascript lightbox for showing images on my site. I am trying to add smarty code into a html block in the js im using.

I need to put this:

{include file='blocks'|cat:$smarty.const.RL_DS|cat:'fancybox.tpl'}

in between some div tags in a html block in my js file. I have marked the area the code needs to be in, in the js below with "CODE NEEDS TO GO HERE "

Here is a portion of my js.

Code:
{
 wrap:'<div class="fancybox-wrap" tabIndex="-1"><div class="fancybox-skin"><div class="fancybox-outer"><div class="fancybox-inner"></div></div></div> CODE NEEDS TO GO HERE </div>',
 image:'<img class="fancybox-image" src="{href}" alt="" />',
 iframe:'<iframe id="fancybox-frame{rnd}" name="fancybox-frame{rnd}" class="fancybox-iframe" frameborder="0" vspace="0" hspace="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen'+(E?' allowtransparency="true"':"")+"></iframe>",
 error:'<p class="fancybox-error">The requested content cannot be loaded.<br/>Please try again later.</p>',closeBtn:'<a title="Close" class="fancybox-item fancybox-close" href="javascript:;"></a>',
 next:'<a title="Next" class="fancybox-nav fancybox-next" href="javascript:;"><span></span></a>',prev:'<a title="Previous" class="fancybox-nav fancybox-prev" href="javascript:;"><span></span></a>'
}


Obvously its not just a case of putting the smarty in as this does not work.

So any ideas. Thanks
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1653

PostPosted: Mon Aug 22, 2016 8:45 pm    Post subject: Reply with quote

Do you know what PHP is?
Back to top
View user's profile Send private message
elpmis
Smarty Elite


Joined: 07 Jun 2007
Posts: 321

PostPosted: Tue Aug 23, 2016 8:50 am    Post subject: Reply with quote

You can change Smarty delimiters to other values like [[ ... ]] so you woun't get trouble with javascript.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1653

PostPosted: Tue Aug 23, 2016 7:49 pm    Post subject: Reply with quote

There's no trouble with JS, the trouble in the man himself.
He don't understand, what he's doing and/or how Smarty works.
Which inherently implies the understanding of PHP as a SERVER-side scripting.
Back to top
View user's profile Send private message
aidendoyle1981
Smarty Rookie


Joined: 11 Jan 2016
Posts: 9

PostPosted: Wed Aug 24, 2016 12:50 am    Post subject: Reply with quote

I am a newbie with smarty and yep no idea how it works.


All i do know is when I use the ' symbol javascript does not like it at all.


I do know a bit about php and html but my strength lies in css.

The issue is I have to use smarty short coeds to retrieve values.

In relation to the answer
You can change Smarty delimiters to other values like [[ ... ]] so you wouldn't get trouble with javascript.

could you please format
{include file='blocks'|cat:$smarty.const.RL_DS|cat:'fancybox.tpl'}
to show me what you mean

Cheers Lads.
Back to top
View user's profile Send private message
elpmis
Smarty Elite


Joined: 07 Jun 2007
Posts: 321

PostPosted: Wed Aug 24, 2016 7:24 am    Post subject: Re: Putting smarty code in a html block in a javascript file Reply with quote

aidendoyle1981 wrote:
I have marked the area the code needs to be in, in the js below with "CODE NEEDS TO GO HERE "


Ok, please tell us something about the "CODE NEEDS TO GO HERE ".

What's this? PHP? Javascript?
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1653

PostPosted: Wed Aug 24, 2016 2:39 pm    Post subject: Reply with quote

aidendoyle1981 wrote:
I am a newbie with smarty and yep no idea how it works.

Smarty is a PHP code generator.
PHP code.
Which then needs to be run on server to generate some output for client.
If your JS is not generated via PHP script, then Smarty here is of no help to you.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP