embedded template assigns

Posted on 2005-04-21
Last Modified: 2008-03-06

I'm new to the whole PHP and template scene.

I have some code where I assign a value in the template like this:

$search_tpl->assign ('my_choice', '
                <input type="radio" name="type2" value="0" {openmy_checked}>All
                <input type="radio" name="type2" value="1" {my_checked}>My
                <input type="radio" name="type2" value="2" {open_checked}>Open

Now,  only a select few get to see these options, thats why I can't put it straight into the template.

After this, I try to keep the current option selected by grabbing the $_GET data:

if (isset($_GET['type2'])) {
                switch ($_GET['type2']) {
                        case 1: // Me
                                $search_tpl->assign('my_checked', 'checked');
                        case 2: // Open
                                $search_tpl->assign('open_checked', 'checked');
                        default: // All selected
                                $search_tpl->assign('openmy_checked', 'checked');
else {
                $search_tpl->assign('openmy_checked', 'checked');

Now, I'm guess that it doesn't work because in the search.tpl I only have the {my_choice} .

So my question is, how would I go about doing something like this:

$search_tpl->assign('my_choice', assign('openmy_checked', 'checked'));


Any help on this one would be greatly appreciated!
Thank a lot and best regards,
Question by:noshankus
    LVL 49

    Expert Comment

    Could you have something like a hidden input?

    $search_tpl->assign ('my_choice', '<input type='hidden" name="type2" value="0" />');

    I am not sure about the way the template engine works, because there are tons of different ones.


    Author Comment


    Solved the problem by having a switch with 3 options and only then defining the radio buttons.
    Doesn't look nice, but it works =)
    LVL 49

    Expert Comment

    no problems with it.


    Accepted Solution

    Question Closed, 80 points refunded.
    Community Support Moderator

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    A colleague recently asked me about how to give his client a small part of the web site that could be completely under the client's control.  Since I have done this sort of thing before to add emergency banners to a web site, I decided I would creat…
    These days socially coordinated efforts have turned into a critical requirement for enterprises.
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to count occurrences of each item in an array.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now