Include A Php File To .tpl

hi,

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

ex.

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!

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.

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

@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.

@eComLabs


http://forum.cs-cart.com/topic/33663-how-to-add-basic-custom-code-and-or-use-php-include-httpwebpagenamecomfilephp-on-the-homepage/?view=findpost&p=234060

http://forum.cs-cart.com/topic/37010-file-name-for-editing-pre-defined-blocks/?view=findpost&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 = "";
				$.each(data.recs, function(key, val) {
					recs+="" + val.category + "";
				});
				
				$("#model_accessory_one").html(recs);
				
			}
		});
 })

thats all!

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

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).

@eComLabs

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

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!

hi there,

finally I created a new block type of HTML/Smarty

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

{literal}

{/literal}

all wokring nicely.

Thank you tbirnseth & eComLabs.

Thank you for sharing this information