Page 1 of 1

App with different themes

Posted: Tue Dec 04, 2012 7:02 am
by Sdesigns
Hi,

My app, which is now installing fine (Thanks for all the help) will have about 10 different themes.

Is it possible to add the theme choices to the installation, so depending on theme chosen will import a different .sql file?

Thanks

Re: App with different themes

Posted: Tue Dec 04, 2012 10:16 am
by Phil
Hello,

Yes, this is possible. We recommend using a custom field to handle prompting the enduser. For example, this would add a radio field:

Code: Select all

      <field id="mytheme" type="radio">
         <label>Theme</label>
         <text>select a theme</text>
         <options>
            <option value="theme1">Blue</option>
            <option value="theme2">Red</option>
         </options>
         <set>
            <?php
            // code here to set field. value saved as $this->input["field_mytheme"]
            //@note It's possible to leave this code blank and simply use the variable in the install's PHP code.
            ?>
         </set>
      </field>


And this field can be accessed in the install PHP code as:

[code]$this->input["field_mytheme"]

See the docs here:
http://installatron.com/developer/apps

Thank you,
Phil

Re: App with different themes

Posted: Fri Dec 07, 2012 1:44 am
by Sdesigns
Hi,

Thanks for the reply, so how would I use this to select the .sql that is used to populate the database?

Normally to populate a database it would be something like

Code: Select all

$this->db_import("install/assets/install.sql");


Can I then use something like

Code: Select all

$this->db_import("install/assets/$this->input["field_mytheme"].sql");


Thanks again for the help.

Re: App with different themes

Posted: Fri Dec 07, 2012 9:01 pm
by Phil
Hello,

Sure, that will work. Something like this:

Code: Select all

$this->db_import("install/assets/".$this->input["field_mytheme"].".sql");


Thank you,
Phil

Re: App with different themes

Posted: Sat Dec 08, 2012 1:11 am
by Sdesigns
Phil wrote:Hello,

Sure, that will work. Something like this:

Code: Select all

$this->db_import("install/assets/".$this->input["field_mytheme"].".sql");


Thank you,
Phil


Hi Phil

I understand the punctuation marks and parenthensis, but why the full stop at the beginning?

Code: Select all

".$


Thanks

Tony

Re: App with different themes

Posted: Mon Dec 10, 2012 4:53 am
by Phil
Hello,

This due to PHP's string concatenation syntax. See:

http://php.net/manual/en/language.operators.string.php

Thank you,
Phil

Re: App with different themes

Posted: Fri Dec 28, 2012 2:50 am
by Sdesigns
Hi Phil,

So far it is working great, thanks for all your help.

Is it possible, and if so then how :) , to use a dropdown instead of radio buttons?

Also, what would be the correct way to have a radio button checked by default in the xml file?

Thanks again

Tony

Re: App with different themes

Posted: Fri Dec 28, 2012 4:47 am
by Josh
Greetings,

Simply change the type to "select" and the options will show up as a dropdown menu.

A default option can be set by adding a "default" parameter. This can be defined using PHP code or as a static XML value. Eg.

Code: Select all

      <field id="mytheme" type="radio" default="theme1">


or:

Code: Select all

      <field id="mytheme" type="radio">
            <default>
            <?php return "theme".mt_rand(1,2);?>
            </default>


Best regards,
Josh