Hi,
I’m a long time PHP developer using ModX for the first time, so snippets is where I am focused.
Anyway, on a page is HTML table. I wrote a snippet that returns an extra dynamic row - pulling info from the database. The db connection and data is fine. However I placed the snippet in the appropriate place in the HTML, like this:
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
[[ballylocation]]
<tr> (following this is more HTML table code)
The [[ballylocation]] snippet itself includes a <tr> through a </tr> as what gets returned. It seems it should just stick that extra row right there as the first row of the table. When I save the page, it forces the snippet to the top - like this:
<p>[[ballylocation]]</p>
<p> </p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
So two things - it’s in the wrong place, and it got surrounded by <p></p>
Trying to outsmart it I added some code to the snippet so the snippet is now a full table with the one row, the snippet starts and ends with <table>...</table>.
Saved that and it worked, sort of. It put a separate small table on top of the longer HTML hard coded table. Okay, however the snippet still ends up in paragraph tags: <p>[[ballylocation]]</p>
End the result is the dynamic data shows up, on top of the page BUT since that whole snippet based table is inside the <p></p>, it formats differently from the HTML table.
How do I get a snippet to not end up surrounded by paragraph tags? - that’s my main question.
And if anyone can figure out why the snippet gets kicked out of the HTML table code, I’m all ears about that too!
Thanks,
KenB
This one irks me... and it’s the Tiny MCE editor that’s to blame.
The way to solve it is to turn off rich text in the page settings, refresh and then set the code exactly how you want it. As long as a WYSIWG editor isn’t an essential on that page that’ll solve it.
I guess, in fairness to Tiny MCE, it formats code correctly how it sees fit. But it’s not privy to code that sits outside of the page, so it can’t always do things right.
Sounds like you are using echo to produce the <tr> </tr> in your snippet. To get more reliable results you should do something like this:
<?php
$output ='';
if( blah blah... ){
$output .='<tr> blah blah</tr>';
}
return $output;