Jump to content

Custom Markup in Module (without form or table)


kongondo
 Share

Recommended Posts

Hi all,

Let's say I want a landing page for a process module. 

If I wanted a form on the landing page - InputfieldForm comes to mind

If I wanted a table - MarkupAdminDataTable

However, on that page, I don't want a form nor a table. I just want my plain HTML to be rendered. I have no need for Inputfields on this page. 

 
Next, I look at InputfieldWrapper - But the docs say:
 
InputfieldWrapper is not designed to render an Inputfield specifically, but you can set a value attribute containing content that will be rendered before the wrapper
Not my intended question, but I don't get this bit "but you can set a value...". How? I tried different stuff without success.
 
Final up (to the best of my knowledge) is InputfieldMarkup. This code does work:
$test = $this->modules->get('InputfieldMarkup'); 
$test->value = "<p>My test HTML output</p>";
//return $test->renderValue();//doesn't work. Markup not output
return $test->render();//works fine

I get my HTML output in the right place in my module landing page in the PW Admin without any extraneous markup. 

<div id="content" class="content">
  <div class="container">
    <p>My test HTML output</p>
  </div>
</div>
<!--/#content-->

But is this the way to go? The name of the class sort of suggests that it should be used with Inputfields. If I try to add my HTML independent of these methods, the markup is not output in the right place in my module landing page in the PW admin, i.e. between the <div class="container"></div>. It will be thrown to the top of the page, somewhere weird like before the <body> tag. So, am I on the right track here or there is a "more appropriate" way?

 
By the way, I tried to use renderValue() but it doesn't output anything? What's the use case for this method? The docs say:
 
Render just the value (not input) in text/markup for presentation purposes
I have studied some other modules but have not seen something similar to this sort of landing page. Thanks.  :)
Link to comment
Share on other sites

Just checking: you've tried creating output (into a variable, such as $out = "my markup goes here") and returning that variable (return $out), not just echoing it out directly.. and it doesn't work?

It definitely should, so I'm guessing there's something weird going on. If you could post some sample code that causes issues, I'd be happy to take a closer look.

Answer to your non-intended question is that you'll still have to render some inputfield markup there. This is probably easiest to explain with some code. Example below will output "my value" first, then render any inputfields this wrapper contains (in this case just one markup inputfield with value "some markup.")

$wrapper = new InputfieldWrapper;
$wrapper->attr('value', 'my value');

$inputfield = new InputfieldMarkup;
$inputfield->value = "some markup";

$wrapper->add($inputfield);
echo $wrapper->render();
  • Like 3
Link to comment
Share on other sites

Thanks Teppo! That was it. I was committing the cardinal sin - echoing $out in the method instead of returning it! (grrr!). It works as intended. That markup is output in the right place.

Thanks for answering the other question too! For some reason, I didn't realise I could render an InputfieldWrapper like that. I don't know where I got the the idea that an InputfieldWrapper always goes with a form! , i.e, that I would have to do something like $form->add($wrapper) ; in the end before returning the form. Hence my original question; I didn't need form markup and was wondering how to avoid it. 

Cheers.

Edit:

I can't find the "solved/best answer button"...

Edited by kongondo
Link to comment
Share on other sites

I don't know where I got the the idea that an InputfieldWrapper always goes with a form!

InputfieldWrapper is the base class for a Form, Fieldset or Tab (InputfieldForm, InputfieldFieldset, etc.) It implies an Inputfield thats purpose is to contain other Inputfields. While Forms, Fieldsets and Tabs represent specific things, a regular InputfieldWrapper just acts as a wrapper/container for Inputfields, without any kind of visual representation. Because it is a type of Inputfield, it can take the place of a single Inputfield, while actually containing many of them. 

  • Like 5
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...