Is there a way to print field content without getting all the markup? I'm new to Drupal, but I'm aware of the field.tpl.php, however, I'm just wondering if there's a quicker way to get the content in a node--custom.tpl.php. It would compare to Wordpress's <?php echo get_field('field_name'); ?>
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
You simply can use PHP's
strip_tags()
like so:Well, apart from using field.tpl.php, I can think of 2 solutions:
first:
Use a php snippet to strip html tags in your template.php.
in your template.php
then call the function
mytheme_strip_html_tags($field_name)
if you use several themes, however, you need to copy this snippet to each one of them.
EDIT: You can make a module and place that snippet inside. This way it works with every theme.
second:
Download the tokens module. Tokens are references to your fields. Tokens module have a output mode that strips html for you. [field_name-raw]
You need to follow instructions in how to add tokens, but is not that difficult.
You have access to the $node variable inside a node.tpl.php, so:
should work... note that many fields will hide their data inside arrays (for multiple value fields, etc) so you may need to do a bit of:
...to figure out the exact path to the data you need.