Skocz do zawartości
Zaloguj się, aby obserwować  
Invisionize.eu

[Invisionize.eu] Michael's Blog - IN_DEV and skin templates/CSS files

Polecane posty

I have always found the way IPS recommends doing skin templates for applications to be very clunky, and I have never gotten it to work properly. For reference, the official documentation for it is here:

http://www.invisionpower.com/support/guides/_/advanced-and-developers/miscellaneous/developers-mode-r147

http://www.invisionpower.com/support/guides/_/advanced-and-developers/application/using-skin-templates-r154

The basic idea here is that you need to enable IN_DEV, then do some funky building of files and folders, then run some tools, then you get the ability to work with your skins in a non-familar format. You then have to run several more tools to build the skin templates for release with your product. I find this to be complicated, error prone, and confusing. So I wanted to present the method I use for creating my skin templates in all of my products. I have used this method for years on dozens of different products, so it does work. It is, of course, not the 'approved' way of doing things, but I wanted to present it in case some find it easier. I've talked about this method a bit in previous entries, but this time I wanted to devote an entry just to this, so as to make it a good resource for others.

First off, I enable IN_DEV on my localhost test board, but I only have it enabled in the Admin CP. The way I do that is by adding a line like this to my forum's constants.php file:

define( 'IN_DEV', ( IPB_THIS_SCRIPT == 'admin' ) ? 1 : 0 );
The reason I have this enabled only in the Admin CP is that doing this gives me access to all of the development goodies I need in the Admin CP, but doesn't make the public side act like it's in development mode. When the public side thinks IN_DEV is enabled, it tries to load skin templates from the master skin folders, and I just don't want to mess with all of that.

So now that I have IN_DEV enabled in the Admin CP, I can create any skin templates I want inside the familiar interface the Look & Feel tab gives you normally. Of course, I add these templates to the default 'IP.Board' skin. The text box there lets you put in just what code the template needs, without needing to code any of the nonsense that it normally required (defining $IPBHTML, making sure you don't mess up the EOF; stuff, having //--starthtml--// and //--endhtml--// comments, etc.). You can happily just write your templates, and pop back over to the public side in another browser tab, and refresh to see your updates.

Stylesheets work the exact same way. If you application or hook requires a new stylesheet, simply add it to the IP.Board skin using the built-in mechanism for this on the Look & Feel tab, and add the CSS code it needs there.

Once you have your application/hook all coded up and the templates/stylesheets have the code in them you want, getting them exportable is fairly easy too. Since we did these in the Look & Feel tab by adding these to the IP.Board skin, they are only currently items that exist there. We need to move them over to the master skin to make them something your product can pull into its XML files for redistribution. I do this process in phpMyAdmin by modifying the database directly.

Let's start with templates. In phpMyAdmin, browse your forum's ibf_skin_templates table (like all database things, be sure to replace ibf_ with whatever SQL table prefix you use). What we need to do is find these templates you just added. Depending on how complex your product is, it may require some specific filtering in a SQL query to pull all of its templates. If it's just a couple, you can typically just sort the table by template_id descending and the ones you want to look at will be there at the top.

Once you've identified which rows are your templates, the first thing you want to do is look for any rows there in which the template_set_id column is 0. This is a row that gets created as soon as you made that template. It may or may not have the correct template code in it, but there will be a similar row with the same template_name value where the template_set_id value is 1. What we want to do is delete all of these rows where the template_set_id equals 0 for your new templates. Be very careful at this stage, before you actually confirm that deletion, verify that each row you're deleting has a corresponding good row which will be kept. There is no undo here!

Now, once you've deleted the bad rows, what you want to do is edit each of the remaining rows. How you do this will vary on your version of phpMyAdmin, some new versions make it so you can check a box on each row and then edit them all at once. You can do that, or you can edit them individually. What you want to do for each row, though, is this: you need to change the values of certain columns in that row to these new values:

  • template_set_id: 0
  • template_removable: 0
  • template_added_to: 0
  • template_user_added: 0
  • template_user_edited: 0
  • template_master_key: root
Setting each of these values makes this row become the master skin version of this template. Do this for each template in your product.

The process for CSS files is similar. Browse the ibf_skin_css table, look for rows for your new stylesheets, delete the rows where css_set_id equals 0 (if any), then edit the rows where css_set_id equals 1 and set these fields:

  • css_set_id: 0
  • css_added_to: 0
  • css_master_key: root
Now that your templates and stylesheets are saved as the master skin copies, it's a good idea to jump back to your Admin CP and rebuild all of your skins. After this is done, you should be able to check out the different skins and see the templates and stylesheets you added showing up, and looking as if they are not custom or edited.

To now export these into the application xml folder for redistribution, you do this by going to the Template Tools page in the Admin CP and running the 'Export HTML Templates Into Application Directories' and 'Export CSS Into Application Directories' tools. With this method above, you should have no need to ever run any of the other tools listed there. Do note that you do need to have your application's information.xml file set up correctly to identify which skin template groups should be included, the instructions for setting that up properly can be found here. And then for stylesheets, they will only be exported through this method if you have correctly set the css_app value to your application's key, that is something you define when creating the stylesheet by launching the CSS properties popup on the Look & Feel tab and setting the 'Application Key' setting. If you didn't do this, go back to phpMyAdmin, edit the appropriate row in ibf_skin_css, update the css_app value, and then re-run the 'Export CSS Into Application Directories' tool.

This should be all you need to do to manage this aspect of your mod creation. It may look daunting, but I find it to be pretty simple. At the very least, I do encourage you to give it a try on a test board to see if it's easier to do than the standard method. Getting this setup is a simple thing to do, creating the templates/CSS files is done through the standard Admin CP controls, and then you just need to do a few minutes of manual work in your database to move your stuff to the master skin in preparation for exporting it. Heck, if one were so inclined, I'm sure a quick tool could be created to manage that aspect as well.

Let me know what you think, or if any of this was confusing.

Zobacz Artykuł w pełnej wersji

Udostępnij ten post


Link to postu
Udostępnij na innych stronach
Gość
Temat jest zablokowany i nie można w nim pisać.
Zaloguj się, aby obserwować  

  • Kto przegląda   0 użytkowników

    Brak zalogowanych użytkowników przeglądających tę stronę.

×

Ważne informacje

Kontynuując przeglądanie strony, wyrażasz zgodę na używanie przez nas plików cookies.