Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2018-11-28 08:40:47

AdamK
Member
From: Kraków, Poland
Registered: 2009-08-11
Posts: 47

How to work with templates and styles using git

Hi :)

After 7 years or so I have returned to TXP, as some of my old – but still well being – sites need some attention.

What I immediately found missing when trying to update templates with try/fail/repeat approach of a person, who has long forgotten all the TXP DSL is versioning. Without git support I feel as if I was moved back in time to pre-svn era.

How to integrate versioning in the workflow? I need to be able to work with templates, js, css in a version-controlled environment to be able to work at all: currently, due to the lack of any support for reverting changes in templates, I feel as if my experiments were open heart surgery with no anaesthesia :(

An additional benefit of git-controlled flat file support: I find extremely simplistic internal editor to be counterproductive with no syntax/intellisense support, no basic reformatting and all the other advantages of 2018 state-of-the-art IDE. And given the openness of such a tools like Visual Studio Code writing a plugin parsing TXP DSL would not be a major problem (I could help with that: although I have completely forgotten PHP since 2011, JS is my natural environment at the moment).

Actually the only obstacle I don’t know how to overcome is to teach TXP to use filesystem in place of DB as a source of templates and assets.

After a while of recalling old memories: cnk_versioning seems to be all dead by now… And I have found my own post from 2011 about the same issues

Yours
A.

Last edited by AdamK (2018-11-28 08:43:22)

Offline

#2 2018-11-28 08:58:08

jakob
Moderator
From: Germany
Registered: 2005-01-20
Posts: 3,159
Website

Re: How to work with templates and styles using git

Welcome back, Adam. Good news, it is possible. cnk_versioning was first superseded by rah_flat / oui_flat, and those have in turn been superseded in the most recent 4.7.x version of Textpattern by themes – page templates, forms and styles – that can be imported/exported from the admin side and, more importantly, be saved as files that you can manage in a git repo or similar.

You’ll find them in the /themes folder in your Textpattern root directory and a new pane called “Themes” under the “Presentation” menu allows you to manage them. See the docs for further information.

During development, the plugin etc_flat is a great help. When your site status is set to “Testing” or “Debugging” and the plugin is activated, Textpattern sources the page templates, forms, etc. from the disk rather than the database allowing you to work with your favourite code editor until you’re happy and then import the theme to database when you’re ready. It’s not quite as immediate as the old cnk_/rah_/oui_ method (which rather ruthlessly cleared the templates in the database on every load) but in practice is workable, especially when developing on a local webserver. Tip: if you create new page templates (as opposed to revising an existing one), you need to import your theme to the database first in order to be able to set them in the sections panel.

Personally, I mostly keep my css, js, fonts, etc. in a separate assets folder (e.g. separately compiled from sass files) and only manage page templates and forms in the themes but in the current dev version, there’s now also an “advanced settings” switch with the option to specify other file types – such as js – that can be included in the themes folder. That replaces plugins such as rvm_css and spf_js.

BTW: if you’re updating very old sites, you may want to use the most recent dev version as it includes a fix to the update routine that sometimes stumbled over database restrictions on newer servers.

EDIT: I’ve read your past post now. The newest dev version (upcoming 4.7.2) also allows you to add new form categories and specify associated file types (you need to activate “advanced settings” in Admin › Preferences to make those settings show). More recent versions of txp have obviated the need for some of the plugins you mentioned, e.g. txp:header (you can see others marked in the tag reference as well as expanded general tag attributes here). Other things like improved image handling are still upcoming, and things like the sitemap are now easily constructed as page templates using txp:header (there’s also rah_external_output for that).


TXP Builders – finely-crafted code, design and txp

Offline

#3 2018-11-28 10:23:16

philwareham
Core designer
From: Farnham, Surrey, UK
Registered: 2009-06-11
Posts: 3,093
Website

Re: How to work with templates and styles using git

To reiterate what Jakob said, this is how I use Textpattern themes with git (GitHub).

  1. Create a git project. In a public directory of that project install and set up a local Textpattern 4.7.x version (with something like MAMP). This will be your web root. Use .gitignore files to ignore the Textpattern instances themselves when version controlling your work).
  2. Create a src directory and use that for your Textpattern theme files, any JS, Sass, CSS or whatever that the site will need.
  3. Use a build script such as Webpack, Grunt, Gulp, etc. to compile those src files into the public folder. I generally have a public/assets/ directory where all compiled/minified CSS and JS and suchlike are stored (i.e. I don’t store those in Textpattern database). Compile Textpattern template files (forms and pages) to the public/themes/your-theme-name/ directory.
  4. Use your IDE of choice to write code.
  5. Either use etc_flat as mentioned above, or manually import that theme within the Textpattern admin side ‘themes’ panel when you make changes. That will inject the latest theme code into your database. There are plans to have a ‘web hook’ URL you can ping to automatically inject the theme files without manual intervention but that feature is upcoming (in the meantime etc_flat plugin is the solution).
  6. View the local site.
  7. When ready to go live, move that local site to your live server.

That is all version controlled and easily manageable, and all assets can be cached as normal as in any flat file site.

For a few examples of this workflow, see:

github.com/textpattern/textpattern-default-theme
github.com/textpattern/textpattern-com-website
github.com/philwareham/textpattern-bootstrap (work-in-progress)

Offline

#4 2018-11-28 12:52:50

AdamK
Member
From: Kraków, Poland
Registered: 2009-08-11
Posts: 47

Re: How to work with templates and styles using git

Absolutely amazing, thank you for the immediate response :) I think some of my sites will get second life this week!

Yours
A.

Offline

#5 2018-11-28 13:04:30

philwareham
Core designer
From: Farnham, Surrey, UK
Registered: 2009-06-11
Posts: 3,093
Website

Re: How to work with templates and styles using git

Oh yes, I agree again with Jakob – if updating an old site use Textpattern 4.7.2-dev straight from GitHub as that is more robust at updating older sites than the 4.7.1 release. It’s stable enough for production use, and you can update to 4.7.2 official release in the normal way when that appears (hopefully in next month or so).

Offline

Board footer

Powered by FluxBB