Skip to content

Instantly share code, notes, and snippets.

@ruizfrontend
Last active December 17, 2015 22:48
Show Gist options
  • Save ruizfrontend/5684241 to your computer and use it in GitHub Desktop.
Save ruizfrontend/5684241 to your computer and use it in GitHub Desktop.
Drupal 7 common theme functions
// _-______Basic translatable string_______________________________
<?php print t('STRING !VARIABLE1 @VARIABLE2 %VARIABLE3', array(
'@VARIABLE2' => 'VALUE ESCAPED & FORMATED',
'%VARIABLE3' => 'VALUE ESCAPED',
'!VARIABLE1' => 'VALUE AS IS',
)); ?>
// _-______string translatable with link_______
// _-______Basic link_______________________________
<?php print l(t('TEXT'), 'URL',
array('fragment' => 'VALUE' //#VALUE
'query' => array('QUERY' => 'VALUE')
'attributes' => array(
'id' => 'ID',
'class' => 'CLASS',
'target' => '_blank'
),
);
); ?>
// _-______Print fields with multiple values_______________________________
<?php if(isset($content['FIELD'])): ?>
<?php foreach($content['FIELD']['#items'] as $key => $item): ?>
<?php print $content['FIELD']; ?>
<?php endforeach; ?>
<?php endif; ?>
// _-______print a simple image inside the preivious loop_______________________________
<? print theme('image', array(
'path' => $item['uri'],
'alt' => $item['alt'],
'attributes' => array('class' => 'img-'.$key),
)); ?>
// _-______print a image with image styles inside the preivious loop_______________________________
<? print theme('image_style', array(
'path' => $item['uri'],
'alt' => $item['alt'],
'attributes' => array('class' => 'img-'.$key),
'style_name' => '480x350',
)); ?>
@ruizfrontend
Copy link
Author

Some Drupal theming snippets I use too often

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment