Jump to content

Outputting field data within a cms page / possibly hanna code related?


cosmicsafari
 Share

Recommended Posts

Hi all,

I have what on the face of it what seems like a simple addition I want to add to a template, but im a bit stumped in how to achieve it.

Basically I have a global page reference field that allows a user to order the output of a given template file.

So this global field sits on its own template/page, and on it you can just order a list of named items, nothing fancy.

Now I can use this order the front end no problem by just using the field name and a foreach loop.

But I have no idea if that same output is possible within a different page/template within the cms.

All I am wanting to do on this other template file is just output the content of the global field, just so that anyone on a page using the second template has the current global order for reference. Nothing fancy, doesn't have to do anything just display a list of items in the order set on the global settings page.

I figured this would be fairly simple to do, as I have setup many textual type outputs for backend module configs however in this instance im not sure what I need to do to get similar output within the cms page using said template.

I had thought hanna code might be useable but I can't see anyway to get it to execute from within the cms, albeit the page where you can set up the php snippet does do exactly that when you test it.

Any ideas on how I could achieve the above?

Screen shots of what im trying to explain incase it helps any.

 

(Global settings ordering screenshot)

image.thumb.png.14bb1313d10357905c85705ab5ef2819.png

 

(My attempts at outputting the above, on another cms page with Hannacode, where [[test]] is a snippet that just loops over the above and outputs it in a <li>)

image.thumb.png.4092eef079d968bc02683aff4dcc2047.png

So is it possble to have the output appear there, as in execute the hannacode snippet [[test]] and show me the output like it would do on the frontend?

Any advice would be much apprecriated.

Link to comment
Share on other sites

I think what you are looking for is an https://processwire.com/api/ref/inputfield-markup/ inside your Block Ordering Tab. You can use that to output the markup that is being supplied by your Hannacode. And you don't even need that Hannacode. Because your development template ordering lives on a single page that doesn't change in different contexts. So you can produce the markup for InputfieldMarkup from that page id.

For InputfieldMarkup you can set the property markupFunktion to a closure that outputs your block order. Something like

/** @var InputfieldMarkup $f */
$f = $this->wire->modules->get('InputfieldMarkup');
$f->set('label', 'Development Template Ordering Status');
$f->set('markupFunction', function () {
    $markup = '';
    foreach(wire('pages')->get(yourid)->get('block_order_field') as $block) {
        $markup .= "{$block->title}<br>";
    }
    return $markup;
});
$inputfields->add($f);

 This will output something like

438871294_2023-02-28-095512.png.f74889dc3f5e148617d182ccb6394db9.png

  

  • Like 2
Link to comment
Share on other sites

8 hours ago, gebeer said:

I think what you are looking for is an https://processwire.com/api/ref/inputfield-markup/ inside your Block Ordering Tab. You can use that to output the markup that is being supplied by your Hannacode. And you don't even need that Hannacode. Because your development template ordering lives on a single page that doesn't change in different contexts. So you can produce the markup for InputfieldMarkup from that page id.

For InputfieldMarkup you can set the property markupFunktion to a closure that outputs your block order. Something like

/** @var InputfieldMarkup $f */
$f = $this->wire->modules->get('InputfieldMarkup');
$f->set('label', 'Development Template Ordering Status');
$f->set('markupFunction', function () {
    $markup = '';
    foreach(wire('pages')->get(yourid)->get('block_order_field') as $block) {
        $markup .= "{$block->title}<br>";
    }
    return $markup;
});
$inputfields->add($f);

 This will output something like

438871294_2023-02-28-095512.png.f74889dc3f5e148617d182ccb6394db9.png

  

Ah this looks like its exactly what im looking for. ?

Can I just ask, did you get that code to work in order to take that screenshot, as I am getting a null error on the last line.

image.thumb.png.42e1c9df4f5c81e35df5c9e6e363455c.png

Just curious of your field settings for the runtime fieldtype in this instance incase I need to ammend mine to get the same result.

 

 

Link to comment
Share on other sites

Hi all,

So I ended up editing the snippet to the following which got me around the null error I was encountering.

Figured i'd paste this for anybody else looking for something similar in the future.

<?php
    /** @var InputfieldMarkup $f */
    $f = $this->wire->modules->get('InputfieldMarkup');
    $f->set('label', 'Development Template Ordering');

    $markup = '<ul>';
    $blocks = processwire\wire('pages')->get('template=development_template_ordering_settings')->development_template_ordering;
    foreach($blocks as $block){
        $markup .= '<li>'.$block->title.'</li>';
    }
    $markup .= '</ul>';
    echo $markup;
?>
  • Like 1
Link to comment
Share on other sites

Glad you sorted it out ?

My example was in a mudule's config inputfields context. That is why $inputfields was null in your context. Are you still using Hannacode? You don't really need it.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...