Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By willbxl on
I have create a content type "machines" and I am looking to theme it. At the bottom of each "machine" I would like to create 2 buttons, preview and next. These 2 fields are entity reference of other nodes of the same content type machine.
So I have to create a loop to verify if the field is not empty.
$next = XXXXXXXXXXX
$prev = XXXXXXXXXXX
if ($next != NULL) {
$next_url = XXXXXXXXXXX
else
$next_url = XXXXXXXXXXX
}
if ($prev != NULL) {
$prev_url = XXXXXXXXXXX
else
$prev_url = XXXXXXXXXXX
}
Then I have to print the right field in my buttons.
<?php if($page && module_exists('prev_next')): ?>
<div class="next_prev text-center">
<ul class="pager">
<?php if(isset($prev_url)) : ?>
<li class="previous">
<a href="<?php echo $prev_url; ?>">← Prev</a>
</li>
<?php endif; ?>
<?php if(isset($next_url)) : ?>
<li class="next">
<a href="<?php echo $content->field_next; ?>">Next →</a>
</li>
<?php endif; ?>
</ul>
</div>
<?php endif; ?>
Any idea to replace the XXXXXXXXXXXX? Thank you beforehand!!!!
Comments
One assumes the module you
One assumes the module you are using (prev_next) provides those variables, perhaps they are in $links or not, you'd have to view the node object arrays to find where they are.
BTW, there is no loop, if/else are control structures, loops are for, foreach, while etc.
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
$links does not work :(.
$links does not work :(.
I wrote $node->field_next['target_id']; should work but it does not. It display the url of the node instead of the link to the entity ref.
OK Found!
OK Found!
This code does the job
Thank you for your help!