HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to compo.sr for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.


Correct/best way to appending to javascript templates.

Login / Search

 [ Join | More ]
 Add topic 
Posted
Rating:
#70955 (In Topic #14980)
Avatar

Community saint

I've just finished adding a custom edit button to the comcode editor. Everything works fine, I'm just wondering if there is a better (more upgrade friendly) way of making the javascript changes.

For the php changes, I've got a modified version of get_comcode_editor() in my sources_custom/form_templates.php file. That is the only function in that file. No problems there because it will inherit the rest from the original file in the source/ directory.

But with the templates_custom/JAVASCRIPT_POSTING.tpl, I've added a new function but have also had to include all the functions from the original templates/JAVASCRIPT_POSTING.tpl file because it will not inherit them from it. To avoid this non upgrade friendly situation, can/should I use something like {$JAVASCRIPT_INCLUDE,{$BASE_URL_NOHTTP}/themes/default/templ
ates/JAVASCRIPT_POSTING.tpl} for the original file?

Hope this makes sense.

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#70958
Avatar

You could just put it in the JAVASCRIPT_CUSTOM_GLOBALS, although that would load on each screen.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#70975
Avatar

Community saint

I don't want to get into the bad habit of placing editing code into JAVASCRIPT_CUSTOM_GLOBALS when there is already a proper place for it elsewhere.

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#70977
Avatar

Maybe your suggestion about the include thing is best then. You'll just have to manually reappend that bit each time you upgrade, if that file changes.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#70985
Avatar

Community saint

I was actually thinking of adding the include to the templates_custom/ file to pull in the original, not the other way around, so in theory I wouldn't have to touch anything after an upgrade.

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#70986
Avatar

JAVASCRIPT_INCLUDE takes a template name, rather than a path, so you'd just end up making a loop there I'm afraid.

You could probably do {$BLOCK,block=fileinclude,path={$BASE_URL_NOHTTP}/themes/default/templ
ates/JAVASCRIPT_POSTING.tpl}

and make sources_custom/miniblocks/fileinclude.phpwhich just contains <?php echo file_get_contents($map['path']);.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#70988
Avatar

Community saint

Chris Graham said

JAVASCRIPT_INCLUDE takes a template name, rather than a path, so you'd just end up making a loop there I'm afraid.
I knew there was a problem there, I just couldn't put my finger on it. I knew I just couldn't use "JAVASCRIPT_POSTING" because of the recursion problem and though if that if I use the full path that it would solve that. I totally missed the little clue of the missing ".tpl" in the included file name, indication that it wasn't a simple file include.

Chris Graham said

You could probably do {$BLOCK,block=fileinclude,path={$BASE_URL_NOHTTP}/themes/default/templ
ates/JAVASCRIPT_POSTING.tpl}

and make sources_custom/miniblocks/fileinclude.phpwhich just contains <?php echo file_get_contents($map['path']);.
That sounds like a nice generic solution that I can use for other situations also.

Is there any potential for a security hole here? I'm guessing not as this would be tempcode and not comcode, and therefore will error/be ignored if someone tries to use {$BLOCK,block=fileinclude,…} in say a post.

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#70992
Avatar

correct


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#71038
Avatar

Community saint

Many thanks Chris!

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#71048
Avatar

Community saint

The include works file, just needed to drop "{$BASE_URL_NOHTTP}/" as its already at the base.

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#71095
Avatar

Community saint

Spoke too soon  :o  

While the file is included, its not being parsed for tempcode.

I did my testing in IE originally. It appeared to work, but I did not notice the error icon in the corner.

So I changed fileinclude.php to the following, but it made no difference.

Code

<?php
   $tempcode=new ocp_tempcode();
   $tempcode->attach(make_string_tempcode(file_get_contents($map['path'],FILE_TEXT)));
   $tempcode->evaluate_echo();

What am I missing?

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#71096
Avatar

Oh yes, whoops. make_string_tempcode does a direct objectification of the string, you need template_to_tempcode.
You'll need a       require_code('tempcode_compiler');
call first.
You might also want to put js_minify around it.
You'll need a       require_code('css_and_js');
call first.

Code

<?php
   require_code('tempcode_compiler');
   require_code('css_and_js');
    $tempcode=template_to_tempcode(file_get_contents($map['path'],FILE_TEXT));
   echo js_minify($tempcode->evaluate());


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#71099
Avatar

Community saint

OK, I see now. Thanks.

It doesn't look like js_minify is required as the end result is getting minified anyway. That's good because it means I can keep the miniblock as a generic include rather then a javascript include as follows:

Code

<?php
   require_code('tempcode_compiler');
   $tempcode=template_to_tempcode(file_get_contents($map['path'],FILE_TEXT));
   echo $tempcode->evaluate();

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
There are too many online users to list.
Control functions:

Quick reply   Contract

Your name:
Your message: