Drupal 7 (Print render image on page tpl) - image

I can't seem to print render an image on my page.tpl.php.
This is the code I use:
<?php print render($content['field_image']); ?>
I can get the title to show up though: <?php print $title; ?>
So what am I doing wrong?

Because you're in a page.tpl not a node.tpl, field_image isn't in $content. The only thing in $content should be regions, which contain blocks.
Use this instead: https://www.drupal.org/project/fieldblock
Here you can use fields as a block. Very easy :)

Related

Laravel blade syntax for #if/#endif spacing issueif

what is the similar blade syntax for the following code?
<?php if(...):?>abc<?php else:?>cde<?php endif;?>
the code
#if(...) abc #else .... is no good as it ads a space before and after the "abc" the code #if(...)abc#endif (no spacing before and after html string) generates error ...
Thanks
Solution
The correct solution for this problem would be following:
#if(1==1){{ '1' }}#endif
This happens often and makes problem with "space sensitive" parts of code like values in <option> tags.
Having the #if(1==1) 1 #endif would be compiled to following which shows empty spaces around the number:
<?php if(1==1): ?> 1 <?php endif; ?>
Solution code would be compiled to this code:
<?php if(1==1): ?><?php echo e('1'); ?><?php endif; ?>
Which pretty much explains why this won't make additional spaces.
Did a bit more research and it looks like there is no solution as there is no spaceless tag in blade. I found a solution from someone who wrapping his string in extra hml tags (so that is easy as he ads spaces before and after the tag and the string inside tag si spaceless) but in my case I just need a string no spaces before and after ... I will go the old fashion php way ...
Try this:
#if(...) {{ 'abc' }} #else
I've run into similar problems with spaces.
A workaround I use is this:
Put your if statement into php tags
#php
$myVar = 'abc';
if(...) $myVar = 'cde';
#endphp
and then echo the defined variable
{{$myVar}}
It's a workaround, but I still think we always should remember that it's a PHP environment...
So, simply:
#php
if(...) echo "abc";
else echo "cde";
#endphp
I have found the solution in case there is space issue between #if()#endif and #if.
I have replaced the #if() #endif with the {{$wardname}} variable to be printed using {{$wardname}}#if and its removed conflict with #endif & #if
and applied logic like:
if($city->wardname!="") {
$wardname = "(".$city->wardname.")";
}else{
$wardname = "";
}
Implemented it as:
{{$wardname}}#if
The correct syntax is:
#if(...)
abc
#else
cde
#endif
I never saw unwanted spaces with this one.

How to get mian image url form the resized one in wordpress?

I need a help. I need to get the main url of an image uploaded in wprdpress from the url of the re sized one's url. If possible the link of the attachment. Experts please help. Thanks in advanced.
Example-
re sized url-
1. http://www.example.com/wp-content/uploads/2013/05/image-1-90x120.jpg
2. http://www.example.com/wp-content/uploads/sites/9/2013/01/image-1-1040x320.png
3. http://www.example.com/wp-content/uploads/custom_upload_folder/image-1-430x210.jpg
what i'm looking for-
1. http://www.example.com/wp-content/uploads/2013/05/image-1.jpg or http://www.example.com/?attactment_id=12
2. http://www.example.com/wp-content/uploads/sites/9/2013/01/image-1.png or http://www.example.com/?attactment_id=12
3. http://www.example.com/wp-content/uploads/custom_upload_folder/image-1.jpg or ttp://www.example.com/?attactment_id=12
I can't use regex as i'm novice at this. again i can't use substr as image sizes of the resized ones are different.
attactment_id is the attachment id if the image is uploaded through the wordpress media uploader.
Thanks a lot.
You may not do it with substr, but some other string operations may help. This will work but I wouldn't recommend using it as it's not very efficient (too many var assignments) and should just give you an idea. However you may still use it if you're not going to parse these urls with some heavy production code.
$url = 'http://www.example.com/wp-content/uploads/2013/05/image-1-90x120.jpg';
list($first, $second, $third, $forth) = explode("-", $url);
echo $first.'-'.$second.'-'.$third.'.jpg';
There are plenty of examples of how to work with strings, especially with explode and implode functions, in order to make it efficient and more elegant.
On the other hand, I don't believe that Wordpress can anyhow retrieve back the original url out from the ones you have provided.
Using this code get main upload image url:
<?php
while ( have_posts() ) : the_post();
$image_id = get_post_thumbnail_id();
$image_url = wp_get_attachment_image_src($image_id,'full');
?>
<?php if ( has_post_thumbnail() ) { ?>
<img class="img_slide" src="<?php echo $image_url[0]; ?>" alt="<?php the_title(); ?>" />
<?php
endwhile;
wp_reset_query();
?>

Magento echo attribute

I have a problem with my magento. I want echo some attribute, it works fine but why this return number and not text?. For example it return number 7, but I want text sold Out.
<?php print $_product->getCustomStockStatus(); ?>
try
echo $_product->getAttributeText('custom_stock_status');

Display images from a folder on website dynamically. Foreach using Smarty

I want to display random images from a folder on my website
example: ../images/
I already thought of using a foreach construction only I don't know how to implement it in the code.
<ul>
{foreach from=../images/ item=imagelink}
<li><img src="{$imagelink}" width="100" height="100" alt=""/></li>
{foreach}
</ul>
I hope someone has a solution I already searched a lot but couldn't find a solution.
I also want to show lateron all the images that are in that folder.
You'll probably want to create your list of random images in PHP, then assign the array to a Smarty variable. Then you'll be able to iterate over the array with a foreach and create your list elements.
<?php
// create array of random images into $images
$smarty->assign(images, $images);
?>
{* template *}
<ul>
{foreach from=$images item=image}
<li><img src="{$image}"/></li>
{/foreach}
</ul>
#paul-delre working properly, so I take the url of all the images in that directory use
$files = glob("img/*.*");
and
$smarty->assign(images, $files);
Thanks for your help :-)

How can I create a simple internationalization (i18n) example in Kohana v3.0.6.2?

I've been trying to make i18n work: Just to display a string with 2 different languages. I followed this tutorial, but I think the author is not using Kohana 3.
It basically consist on creating a langauge file (pl.php) file in the i18n folder, and add the following:
<?php
$translations['Good Morning'] = 'Magandang Umaga';
Then changing the locale to pl.
and finally the output in the view file:
<?php echo __('Good Morning'); // would produce 'Good Morning' ?>
I really got lost in the tutorial.
Can anyone give me a small example of using internationalization (i18n) in Kohana v3.0.6.2?
Thanks in advance!
this is how your i18n/pl.php file should look like:
<?php defined('SYSPATH') or die('No direct script access.');
return array(
'Good Morning' => 'Magandang Umaga',
);
you can't copy everything that you see from a ko2 tutorial
I think you need to use the key from the translations file. i.e.
<?php echo __('good_morning'); // would produce 'Magandang Umaga' if the locale was 'pl' ?>
but you can also use real words as the key, so in your pl.php file you would have:
$translations['Good Morning'] = 'Magandang Umaga';
and then you can use:
<?php echo __('Good Morning'); // would produce 'Magandang Umaga' if the locale was 'pl' ?>
in your view.

Resources