How to show content of a a specific URL in Smarty template? - smarty

Following is my code snippet from smarty template :
<div id="entrancelist">
<h2 class="heading">My Packages</h2>
{if $user_study_test_packages.test}
<ul class="entrancelist">
{foreach from=$user_study_test_packages.test item="user_test_packages" key=key}
<li>
<h4>{$user_test_packages.pack_name|capitalize:true}</h4>
{if $user_test_packages.pack_expiry_date1 >= $current_date }
<div class="fr"><span class="expiry">Expiry : {$user_test_packages.pack_expiry_date}</span></div>
{else}
<div class="fr"><span class="expiry_dt">This package is expired on {$user_test_packages.pack_expiry_date}.</span></div>
{/if}
<p class="descp">{$user_test_packages.test_pack_desc}</p>
<div class="srtest"> </div>
</li>
{/foreach}
</ol>
{else}
You haven't bought any online test packages
{/if}
</div>
Now what I want to do is reaplace the text "You haven't bought any online test packages" with the content of different URL say www.google.com But I'm not understanding how should I achieve this. Can anyone help me out in this issue? Thanks in advance.

Why not keep PHP separate from the template?
Maybe do this in your php code,
<?php
$gcontent = file_get_contents('http://www.google.com');
$smarty->assign('gcontent',$gcontent);
?>
Then you can use {$gcontent} in your template.
You can even use query string parameters with the URL if you wanted to. More info on the php function.
http://www.w3schools.com/php/func_filesystem_file_get_contents.asp

Something like this works for me in Smarty 3, but some might not consider it very elegant:
...
{else}
{file_get_contents('http://www.google.com/')}
{/if}

Related

CS Cart - Show Three Level of Categories on Catalog and Top Category Page

For CS-Cart Multivendor, Version 4.15.2
How can we display 6 Sub-Categories-Level-1 and 3 Sub-Categories-Level-2 on mydomain.com/catalog page, similar to https://my.indiamart.com/ or https://dir.indiamart.com/
Then how to display 5 Sub-Categories-Level-1 image and name as displayed on https://dir.indiamart.com/
How can we display All Sub-Categories-Level-1 and 5 SubCategories-Level-2 on individual Category Page like below along with Level-1 and Level-2 Images
https://dir.indiamart.com/industry/builders-hardware.html
Finally Display SubCatetory-Level-2 and All Sub-Category-Level3 like
enter link description here
I think there is some modification required in views\categories\catalog.tpl and categories\components\subcategories.tpl.
Also some HTML and css related help is highly appreciated for user friendly view on all devices.
Thanks.
categories_multicolumns.tpl
{split data=$categories size=$columns|default:"3" assign="splitted_categories"}
{strip}
{foreach from=$splitted_categories item="scats"}
{foreach from=$scats item="category"}
{if $category}
{$href=$category|fn_form_dropdown_object_link:$block.type}
{if $category.main_pair}
{include file="common/image.tpl"
show_detailed_link=false
images=$category.main_pair
no_ids=true
image_id="category_image"
image_width=$settings.Thumbnails.category_lists_thumbnail_width
image_height=$settings.Thumbnails.category_lists_thumbnail_height
class="ty-subcategories-img"
}
{/if}
{$category.category}
{/if}
{/foreach}
{/foreach}
{/strip}
{capture name="mainbox_title"}{$title}{/capture}
subcategories.tpl
{if $subcategories}
{math equation="ceil(n/c)" assign="rows" n=$subcategories|count c=$columns|default:"3"}
{split data=$subcategories size=$rows assign="splitted_subcategories"}
<ul class="subcategories clearfix">
{hook name="categories:view_subcategories"}
{foreach from=$splitted_subcategories item="ssubcateg"}
{foreach from=$ssubcateg item=category name="ssubcateg"}
{if $category}
<li class="ty-subcategories__item">
<a href="{"categories.view?category_id=`$category.category_id`"|fn_url}">
{if $category.main_pair}
{include file="common/image.tpl"
show_detailed_link=false
images=$category.main_pair
no_ids=true
image_id="category_image"
image_width=$settings.Thumbnails.category_lists_thumbnail_width
image_height=$settings.Thumbnails.category_lists_thumbnail_height
class="ty-subcategories-img"
}
{/if}
<span {live_edit name="category:category:{$category.category_id}"}>{$category.category}</span>
</a>
</li>
{/if}
{/foreach}
{/foreach}
{/hook}
</ul>
{/if}

How to properly get the value contained inside a section using XPath?

having the following HTML (snippet grabbed from the web page I wanted to scrape):
<div class="ulListContainer">
<section class="stockUpdater">
<ul class="column4">
<li>
<img src="1.png" alt="">
<strong>
Buy*
</strong>
<strong>
Sell*
</strong>
</li>
<li>
<header>
$USD
</header>
<span class="">
20.90
</span>
<span class="">
23.15
</span>
</li>
</ul>
<ul>...</ul>
</section>
</div>
how do I get the 2nd li 1st span value using XPath? The result should be 20.90.
I have tried the following //div[#class="ulListContainer"]/section/ul[1]/li[2]/span[1] but I am not getting any values. I must said this is being used from a Google Sheet and using the function IMPORTXML (not sure what version of XPath it does uses) can I get some help?
Update
Apparently Google Sheets does not support such "complex" XPath expression since it seems to work fine:
Update 1
As requested I've shared the Google Sheet I am using to test this, here is the link
What you need is :
=IMPORTXML(A1;"//li[contains(text(),'USD')]/span[1]")
Removing section from your original XPath will work too :
=IMPORTXML(A1;"//div[#class='ulListContainer']/ul[1]/li[2]/span[1]")
Try this:
=IMPORTXML("URL","//span[1]")
Change URL to the actual website link/URL

Codeigniter summernote fail result

I am using the codeigniter framework with the summernote editor.
If I use a single page in php post without the framework, the result is just like this:
<span style="font-weight: bold;">asdasdasd</span>
But if I use post in codeigniter the result is different, like this:
<span bold;">asdasdasd</span>
style='font-weight: ' is missing..
Why did it happen, and what is the solution?
Thank you for helping.
I got the answer...
in codeigniter don't use :
$_POST['content'] OR $_GET['content']
but use :
$_REQUEST['content']
PROBLEM SOLVED!
I think that is a xss filter problem, try to disable or get the value to false.
$content = $this->input->post('content', FALSE);
I've edited with original summernote example:
<div class="span12">
<h2>POST DATA</h2>
<pre>
<?php print_r($this->input->post(NULL, FALSE)); ?>
</pre>
<pre>
<?php echo htmlspecialchars($this->input->post('content', FALSE)); ?>
</pre>
</div>

Check a string in Smarty

I have a problem with smarty framework, so I need to verify if an image name starts with 'http':
I try this code:
{foreach from=$video->result() item=v}
{if substr($v->image,0,4) eq 'http'}
<img src="{$v->image}" alt="">
{else}
<img src="{$IMG_URL}videos/images/{$v->date|date_format:'%Y'}/{$v->date|date_format:'%m'}/{$v->image}" alt="">
{/if}
{/foreach}
Help me please..Exists another way?
This code should work fine. Probably your data is not set properly.
Consider the following testing code:
PHP file:
class V {
public $image = 'http://rwewreuiuiwre';
}
$smarty->assign('v', new V());
Template file:
{if substr($v->image,0,4) eq 'http'}
http
{else}
non http
{/if}
It works fine. If you change $image to hxttp you get non http message

for-loop interferes with others in web.py

I'm a newbie in web.py.
In my template script exists two FOR loops,it seems that the former(code1) interferes the later one(code2).Each one of them displays well alone,but abnormal when they are in one template script.
code1
$for data in posts:
<div id="title">
<h2>$data.title</h2>
</div>
<div id="marker">
<p>
User
$data.post_on $data.catalog
</p>
</div>
<div id="content">
<p>$data.content</p>
</div>
code2
$for (cat,ctr) in catcollector(posts).items():
<ul>
<li>$cat ($ctr)</li>
</ul>
I'm confused with this phenomenon.Does any one have idea about this? Thanks in advance~
I'm not sure this is your only problem, but it looks like your indentations are not correct. Things within the for loop should be indented.

Resources