kaz Posted August 13, 2021 Share Posted August 13, 2021 I need an if else or if or else to check the following: There is a field aside in each page. A simple info field where you can store info "We are on vacation …". The content is displayed only on this page. Next, there is a settings_aside field in the Global Settings, which is displayed on all pages. The fields are called this way: <?php if ($page->aside) { include('views/blocks/block-sidebar.php'); } else { include('views/blocks/block-sidebar-settings.php'); }; ?> I want, if no field is filled, then nothing is displayed. If both fields has content, the aside field on this page takes precedence. On all other pages the settings_aside content is displayed. block-sidebar.php <div class="uk-card card-bg uk-padding-small uk-margin-small-bottom"> <h6 class="uk-margin-remove uk-text-uppercase uk-text-normal" style="letter-spacing: 1px; margin-bottom: .5rem !important;"><span uk-icon="icon: info"></span> Aktuelles</h6> <?=page()->aside?> </div> block-sidebar-settings.php <div class="uk-card card-bg uk-padding-small uk-margin-small-bottom"> <h6 class="uk-margin-remove uk-text-uppercase uk-text-normal" style="letter-spacing: 1px; margin-bottom: .5rem !important;"><span uk-icon="icon: info"></span> Aktuelles</h6> <?php echo $pages->get('1032')->settings_aside; ?> </div> Roughly it works, but unfortunately not 100 %. Unfortunately the h6 of the templates are displayed. That means I would have to query the headlines via if else with the fields (!?). Just where? In the templates, or in the first if/else query? Link to comment Share on other sites More sharing options...
LMD Posted August 13, 2021 Share Posted August 13, 2021 There are probably as many ways of doing this as there are people who use ProcessWire, but this is how I would do it based on what I understand of your set-up. On the template: <?php // Just include one partial here (the HTML code in 'block-sidebar' and 'block-sidebar-settings' appears identical) include('views/blocks/block-sidebar.php'); ?> Now in "block-sidebar.php" <?php $aside = page()->aside; // first get the current page aside if ($aside === "") { // If the current page aside is empty, try and get the settings aside $aside = $pages->get('1032')->settings_aside; } ?> <?php // Only show the entire block of code if $aside is not empty (if neither the current page nor settings have content) if ($aside !== "") : ?> <div class="uk-card card-bg uk-padding-small uk-margin-small-bottom"> <h6 class="uk-margin-remove uk-text-uppercase uk-text-normal" style="letter-spacing: 1px; margin-bottom: .5rem !important;"><span uk-icon="icon: info"></span> Aktuelles</h6> <?=$aside?> </div> <?php endif; ?> 3 Link to comment Share on other sites More sharing options...
Jan Romero Posted August 13, 2021 Share Posted August 13, 2021 4 hours ago, kaz said: The fields are called this way: <?php if ($page->aside) { include('views/blocks/block-sidebar.php'); } else { include('views/blocks/block-sidebar-settings.php'); }; ?> Not that I have anything to add to LMD's solution, but the shortest answer to your question is this: All you're missing is a condition on the else. } else if ($pages->get('1032')->settings_aside) { 2 Link to comment Share on other sites More sharing options...
kaz Posted August 13, 2021 Author Share Posted August 13, 2021 7 hours ago, LMD said: There are probably as many ways of doing this as there are people who use ProcessWire, but this is how I would do it based on what I understand of your set-up. @LMD In one template, that's a great solution. Thanks a lot for this, it works perfect. 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