kaz Posted April 9, 2021 Share Posted April 9, 2021 I have a template with fields for a settings page. Because the pages that should access the fields from the template 'settings' use a different template 'base', I access them via ID: <?php echo $pages->get('1025')->FIELD; ?> But now I need an if version for some fields. Unfortunately not so easy, because I have nested brackets that lead to an error message. <?php if ($page->get('1025')->FIELD): ?> <?php echo $pages->get('1025')->FIELD; ?> <?php endif; ?> I have tried it with square brackets, but i can't get it work. <?php if ($page->get['1025']->FIELD): ?> How does a if query from a field from another template (ID) looks like? Link to comment Share on other sites More sharing options...
zoeck Posted April 9, 2021 Share Posted April 9, 2021 you forgot an s in $pages Wrong: <?php if ($page->get('1025')->FIELD): ?> Right: <?php if ($pages->get('1025')->FIELD): ?> Link to comment Share on other sites More sharing options...
kaz Posted April 9, 2021 Author Share Posted April 9, 2021 I was searching for hours, I have not seen it – thanks! Link to comment Share on other sites More sharing options...
Pixrael Posted April 9, 2021 Share Posted April 9, 2021 You can use this too: <?php echo $pages->get(1025)->FIELD ?? ''; ?> Link to comment Share on other sites More sharing options...
kaz Posted April 9, 2021 Author Share Posted April 9, 2021 @Pixrael this code replaces the if query in one line? Edit: It has no nested brackets ? 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now