Page 1 of 1

[Solved] Styling a table inside a User Defined Tag

Posted: Sat Oct 06, 2007 6:17 am
by Art-art
Hi,

The following topic has been approached in an other way a few days ago in topic http://forum.cmsmadesimple.org/index.php/topic,15627.msg78041.html#msg78041 (Thanks Alby for learning me a lot already). Since it is moving away from the original question (that included MySQL coding) I decided to ask the question in a hopefully clearer way:

Let's say there is a table like this:

Code: Select all

    <table>
      <tr class="odd">
        <td>Row 1, Cell 1</td>
        <td>Row 1, Cell 2</td>
        <td>Row 1, Cell 3</td>
      </tr>
      <tr class="even">
        <td>Row 2, Cell 1</td>
        <td>Row 2, Cell 2</td>
        <td>Row 2, Cell 3</td>
      </tr>
      <tr class="odd">
        <td>Row 3, Cell 1</td>
        <td>Row 3, Cell 2</td>
        <td>Row 3, Cell 3</td>
      </tr>
      <tr class="even">
        <td>Row 4, Cell 1</td>
        <td>Row 4, Cell 2</td>
        <td>Row 4, Cell 3</td>
      </tr>
    </table>
And the style informatin related to it says:

Code: Select all

      .odd {
        background-color: lightgrey;
      }
      .even {
        background-color: yellow;
      }
      table {
        border: 1px solid black;
        border-spacing: 0;
      }
      td {
        padding: 4px 6px;
        border: 1px solid black;
      }
Now I want to
- put the table inside a User Defined Tag,
- the style information inside a Stylesheet and
- bring is all together in a Template attached to the stylesheet and calling the User Defined Tag?

I already entered clear (so without styling) table information into the User Defined Tag.

Code: Select all

    <table>
      <tr>
        <td>Row 1, Cell 1</td>
        <td>Row 1, Cell 2</td>
        <td>Row 1, Cell 3</td>
      </tr>
      <tr>
        <td>Row 2, Cell 1</td>
        <td>Row 2, Cell 2</td>
        <td>Row 2, Cell 3</td>
      </tr>
      <tr>
        <td>Row 3, Cell 1</td>
        <td>Row 3, Cell 2</td>
        <td>Row 3, Cell 3</td>
      </tr>
      <tr>
        <td>Row 4, Cell 1</td>
        <td>Row 4, Cell 2</td>
        <td>Row 4, Cell 3</td>
      </tr>
    </table>
This works fine.
Now the problem: As soon as I enter the styling of the table into the UDT by entering

Code: Select all

 class="odd"    .... etcetera
it is rejected by CMSMS (Reply from the system:"Invalid code entered."), Why?

Re: Styling a table inside a User Defined Tag

Posted: Sat Oct 06, 2007 8:44 am
by cyberman
Assign the requested values to Smarty.

Then you can use a simple smarty template for output. And switching of even, odd can be done by Smartys cycle plugin.

Re: Styling a table inside a User Defined Tag

Posted: Sat Oct 06, 2007 10:23 pm
by calguy1000
the word 'class' is predefined in php so you have to quote your UDT properly to get the output correct.

try this in a udt"

Code: Select all

echo <<<EOT
<table class='mytable'>
  <tr class='odd'>
     <td>1</td>
     <td>2</td>
  <tr>
  <tr class='even'>
     <td>1</td>
     <td>2</td>
  </tr>
</table>
EOT;
of course, as cyberman said, you can use a template as well, that's the more 'cms' way to do it.

we wouldn't be able to help you much more without a copy of the udt you're working on.

Re: Styling a table inside a User Defined Tag

Posted: Sun Oct 07, 2007 12:01 am
by Art-art
Hi Cyberman and Calguy1000,

To Cyberman:
I don't have that mutch knowledge of Smatry tags. I'd prefer to find some piece of suggested code. How would the code look like? Otherwise give me a clue on where to get an example of a proper smarty tag in this situation.

To Calguy1000:
I've given more of the UDT before and that caused a lot of discussion on the usage of the applied MySQL code. That's why I decided to bring the discussion back to the basic issue. So I constructed a test Page, -UDT and Template just to show the simple table as in the given example.

Perhaps it'll be a good idea to move the table from the UDT to the Template.
I'll try that tomorrow morning (Sunday morning CET) and get back to you.

Kind regards,  Arthur

Re: Styling a table inside a User Defined Tag

Posted: Sun Oct 07, 2007 4:46 am
by cyberman
Arthur wrote: I don't have that mutch knowledge of Smatry tags. I'd prefer to find some piece of suggested code. How would the code look like? Otherwise give me a clue on where to get an example of a proper smarty tag in this situation.
Smarty tags are located in /libs/Smarty/plugins. The tag help is inside the file.

Assigning values to Smarty

http://smarty.php.net/manual/en/api.assign.php

The output with foreach

http://smarty.php.net/manual/en/languag ... oreach.php

Cycling values

http://smarty.php.net/manual/en/languag ... .cycle.php

Re: Styling a table inside a User Defined Tag

Posted: Sun Oct 07, 2007 7:03 am
by Art-art
Hi Calguy1000 and Cyberman,

One simple thing solved my problem.....
calguy1000 wrote:
I made a mistake by writing:

Code: Select all

<table class="mytable">

In stead of:

Code: Select all

<table class='mytable'>

Now it's OK!
I want to thank the both of you for making suggestions. Probably better knowledge of Smarty Tags would have helped me too. This solution however is much easier for a non-programmer as I am.

Kind regards,

Arthur