Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Include A Php File To .tpl Rate Topic   - - - - -

 
  • zakari
  • Newbie
  • Trial users
  • Join Date: 22-Dec 15
  • 5 posts

Posted 28 December 2015 - 08:55 PM #1

hi,

 

reading ways to include a php file to a .tpl file.

 

ex.

<?php
include("test.php");
?>

without hope.. 

 

eComLabs writes - to add a new file at blocks/static_templates folder, then will appear, when going to 'add a block' (clear cache + enable my 

 

tbirnseth writes - Smarty PHP tags {php}code{/php}.

 

nothing worked :(

 

 

any tip?

 

thanks!



 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 12052 posts

Posted 29 December 2015 - 08:59 AM #2

php tags are disabled in more recent versions of cs-cart templater.  Why do you want to include a php file?

 

It would be better practice and style to include your file from (for instance) app/addons/my_changes/func.php and then reference whatever functions you want to call via "smarty modifiers".  I.e.

{assign var="my_tpl_var" value="arg1_str"|my_function:"arg2_str"}

 

And if you're trying to perfom some action ouside the template, just create a function and do your include and processing in there.

 

But remember, the templates are in the UI layer and you're calling to the Business layer.  While it works, it is bad style.


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 21914 posts

Posted 29 December 2015 - 09:47 AM #3

eComLabs writes - to add a new file at blocks/static_templates folder, then will appear, when going to 'add a block' (clear cache + enable my 

 

Where did we write it? I do not believe :)

 

Tony provided you with the good solution

 

But if you describe us your task, possibly we will find another solution for you here


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    Multi-Vendor PLUS           USD 3100 (2775)
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      Multi-Vendor Ultimate       USD 7500 (6000)

 

Posted 29 December 2015 - 10:08 AM #4

@eComLabs
Im at work for the moment, at ~6h I will reply you the actual URL, that you mention, what I said^.
 
 
@tbirnseth
actually, Im native PHP coder, never used a CMS to do a website, a client of mine, needs a search mechanism (which read the product categories from CSCART mysql.tables).
 
The car_search.php :
 
slBoUbw.png
 
 
as you can understand, each combo filled by previous combo selection, when select the last combo (Accessory2) run at http://dispatch=categories.view(greets to  eComLabs for the previous tip).
 
 
 
^All done by jQ (ajax) + PHP in a file car_search.php (I fill the first combo, for sure I can make it HTML and use an ajax call to fill it)
 
the flow :
when combo1_change event fired make a ajax call to car_search_models.php to fill the 2nd combo
when combo2_change event fired make a ajax call to car_search_accessories.php..
etc.
 
now the client needs this^ to be merge @ homepage :)
 
thats why Im searching on how to include...  \
 
I would like to know, how this mechanism can plugged to main page.
 
@tbirnseth thanks for quick reply, seems that the option you provided me isnt fit to my senario^^^,
 
@tbirnseth & @eComLabs looking forward for your solutions based on my needs. :)
 
 
 
thank you.



 
  • zakari
  • Newbie
  • Trial users
  • Join Date: 22-Dec 15
  • 5 posts

Posted 29 December 2015 - 06:02 PM #5

@eComLabs


http://forum.cs-cart...ndpost&p=234060
 
http://forum.cs-cart...ndpost&p=191735

 

ZeFAi4a.gif

 

 
so, I got the JSON result of, this query : 

[b]ask_accessory.php[/b]

select cscart_category_descriptions.category as  category,cscart_category_descriptions.category_id as category_id from cscart_categories  
left join cscart_categories as bb on bb.parent_id = cscart_categories.category_id 
left join cscart_category_descriptions on cscart_category_descriptions.category_id = bb.category_id 
where cscart_categories.category_id=? and lang_code='el' 
 order by cscart_category_descriptions.category

via JQ AJAX

//car_search.php (aka index.php)

 $('#accessories').on('change', function() {
	$("#prg_model_accessory_one").show();
	
		$.ajax({
			url : 'ask_accessory.php',
			dataType : 'json',
			type : 'POST',
			data : {
				"accessory" : $("#accessories").val(),
			},
			success : function(data) {
				$("#prg_model_accessory_one").hide();

				var recs = "<option></option>";
				$.each(data.recs, function(key, val) {
					recs+="<option value='" + val.category_id + "'>" + val.category + "</option>";
				});
				
				$("#model_accessory_one").html(recs);
				
			}
		});
 })

thats all!

 

btw is any addon that can be customized to do the same work ?



 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 12052 posts

Posted 29 December 2015 - 07:31 PM #6

I would create an addon for your extended search and then simply look for your parameters in an index.pre.php controller in the addon and process accordingly (redirecting after the search).


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 21914 posts

Posted 30 December 2015 - 08:48 AM #7

@eComLabs

 

Thank you. Yes, blocks with static templates work in this way. But we did not say that these blocks will accept php tags


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    Multi-Vendor PLUS           USD 3100 (2775)
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      Multi-Vendor Ultimate       USD 7500 (6000)

 

Posted 30 December 2015 - 12:15 PM #8

seems that using a "new html/smarty block" I can embed JS code proper...  which allows me to get the json from php..

 

source - 

http://www.pipiscrew.com/2015/12/cscart-use-smrty-block-allows-us-to-add-custom-javascript-snippet-into-tpls/

thanks!



 
  • zakari
  • Newbie
  • Trial users
  • Join Date: 22-Dec 15
  • 5 posts

Posted 31 December 2015 - 07:21 AM #9

hi there,

 

finally I created a new block type of HTML/Smarty

 

using {literal} tag allows me to use custom JS, sample :

{literal}

<script type="text/javascript">
  $(function() {
     function test(){
          alert("this is a test which allows javascript on a block!");
     }
  })
</script>

{/literal}
 

all wokring nicely. 

 

 

 

Thank you tbirnseth & eComLabs.



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 21914 posts

Posted 05 January 2016 - 08:50 AM #10

Thank you for sharing this information


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    Multi-Vendor PLUS           USD 3100 (2775)
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      Multi-Vendor Ultimate       USD 7500 (6000)