Custom Page Attributes in Next/Prev block

Hello all,

I have added a custom attribute with the handle sample_loc to all sibling pages under a directory called “Work”, and I want to use the Next & Previous Nav block to display that attribute with the page title. I figured I needed to add it to the controller.php file, so I created a custom controller.php file within my custom next_previous template folder, where I have a custom view.php file as well. I can’t figure out how to pass this data through, as I don’t have a strong understanding of how controller.php files work their magic.

Can anyone please point me in the right direction?

Thank you,
Craig

in the block controller view() method use:
$my_attribute = … // whatever you are working out
$this->set(‘my_attribute’, $my_attribute)
Then in the block view, you will have $my_data available as a variable.

However, rather than override the controller, you should be able to do everything by overriding the view or creating a custom view template. Much simpler to do and less risk of unintended consequences.

In the view you should be able to get your attribute directly rather than passing it from the controller.

Thank you for the quick reply, JtF.

Your suggestion sent me right down the path I overlooked.

I ended up accessing the custom attribute directly in my custom view.php file using $nextCollection->getAttribute('my_custom_attribute_handle')

Thank you again!
Craig

I’ll bring up this old thread again.

I want to display the parent page name for the next-prev block in the “Up” section.

I’ve created my own view.php and have read here that the desired customization is possible in this one without modifying the controller file.

However, my rudimentary php knowledge is not sufficient to do this myself.

The parent page name is fetched with:

<?php $parent = Page::getByID($c->getCollectionParentID()); $parentName = $parent->getCollectionName(); ?>

But I can’t get the display to work. What’s the trick?

Thank you,

Jens

@strandbein Can you post the view.php code you’re using?

<?php
defined('C5_EXECUTE') or die("Access Denied.");

if (!$previousLinkURL && !$nextLinkURL && !$parentLabel) {
    return false;
}
?>

<div class="grid-row margin-top-30">

    <div class="column-12">
        <div class="next-previous--divider"></div>
    </div>

    <div class="column-4">
        <?php if ($previousLinkText) : ?>
            <p>
                </i><?php echo $previousLinkURL ? '<a href="' . $previousLinkURL . '">' . '← ' . $previousLinkText . '</a>' : '' ?>
            </p>
        <?php endif; ?>
    </div>

    <div class="column-4 text-center">
        <?php if ($parentLabel) : ?>
            <p class="next-previous--label">
                <?php echo $parentLinkURL ? '<a href="' . $parentLinkURL . '">' . $parentLabel . '</a>' : '' ?>
            </p>
        <?php endif; ?>
    </div>

    <div class="column-4 text-right">
        <?php if ($nextLinkText) : ?>
            <p class="ccm-block-next-previous-next-link">
                <?php echo $nextLinkURL ? '<a href="' . $nextLinkURL . '">' . $nextLinkText . ' →' . '</a>' : '' ?>
            </p>
        <?php endif; ?>
    </div>
</div>

Thank you for taking a look at this.

@strandbein Something like this should do the trick:

$c = Page::getCurrentPage();
$parent = Page::getByID($c->getCollectionParentID());
$parentLabel = $parent->getCollectionName();
if ($parentLabel) {
    ?>
    <p class="ccm-block-next-previous-parent-link">
        <?php echo $parentLinkURL ? '<a href="' . $parentLinkURL . '">' . $parentLabel . '</a>' : '' ?>
    </p>
    <?php
}
?>
1 Like

Great, worked immediately.
Thanks for the help,
Jens

2 Likes