Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2016-02-04 00:48:13

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,729
Website

Re: rah_flat (template file extensions)

mrdale wrote #297552:

I’d like to be able to simply have the following directories under “forms”

  • forms
    • user
      • user_login
      • user_password_reset
      • etc…
    • galleries
      • hero_large
      • hero_small
      • etc…
    • page
      • page_header
      • page_footer
      • etc…

Yeah, I get you with the file organisation … a bit like components in sass. What I meant was how do you envisage mapping these to form names for txp?

When using rah_flat it’s irrelevant for the Presentation > Form tab because you can’t see it (only when you switch it off) but you’ll need to put those in your form="form-name" attribute of your txp-tags. In your example, you duplicate the folder name in the file prefix in all but one case (galleries), so I wasn’t sure.

Maybe a pattern like:

/directory/form.type.txp --> directory.form of type {type}

which would give you:

/forms/user/login.misc.txp --> user.login of type misc
/forms/galleries/hero_large.misc.txp --> galleries.hero_large of type misc

You could also simply ignore the file directory name and only read out the file name, but then you’d need to trap the problem of duplicate forms names in separate directories.

That said, at present you can already name your files like this:

user.login.misc.txp --> user.login
user.password-reset.misc.txp --> user.password-reset
galleries.hero-large.misc.txp --> galleries.hero-large
galleries.hero-small.misc.txp --> galleries.hero-small
page.header.misc.txp --> page.header
page.footer.misc.txp --> page.footer

as the second-to-last extension is always expected to be the form type and dot is an allowed character. According to jukka, it must only:

  • be fewer than 64 characters long,
  • start with an ASCII character, followed by A-z, 0-9, -, _ and
  • end with a file extension

For extra points you could have it create custom form types

At present these are hard-coded in txp.

for extra points have it avoid a foldder called “disabled”.

You can use invalid template names such as starting your form name with an underscore or dot to ‘hide’ forms from rah_flat.


TXP Builders – finely-crafted code, design and txp

Offline

#14 2016-02-04 02:52:40

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
Website

Re: rah_flat (template file extensions)

Good thoughts and clarifications jakob.

For now I use all forms as .misc because form types are functionally irrelevant.

My immediate desire is to have rah_flat simply look at and process forms in subdirectories (simple)

The ideal for rah_flat and textpattern is to

  1. have textpattern provide an interface for creating and using custom form types
  2. have rah_flat use a subdirectory structure that maps to form types instead of name spaces. ie templates/forms/foo/my_form.txp is a “foo” form with a name of “my_form”

Then one could merrily arrange a project in a semantic file structure

Offline

#15 2016-02-04 07:55:01

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,729
Website

Re: rah_flat (template file extensions)

mrdale wrote #297728:

For now I use all forms as .misc because form types are functionally irrelevant.

I haven’t tried this but rah_flat says it defaults to misc if it can’t find the the type, but I’m not sure if you can leave out the misc altogether because rah_flat currently tests if the filename matches the template pattern:

something . something . something

You could try that. As far as I can tell it doesn’t actually check whether the type is one of the standard types, so you could theoretically use anything if txp doesn’t mind.

1. have textpattern provide an interface for creating and using custom form types

This depends on txp accommodating that, and on a plugin being able to modify/override the list. I can’t see any pluggable bits in include/txp_form.php as yet, though. As you say, though, this bit would be irrelevant until the point that you switch off rah_flat.

2. have rah_flat use a subdirectory structure that maps to form types instead of name spaces. ie templates/forms/foo/my_form.txp is a “foo” form with a name of “my_form”

This might work by modifying the form processing bit of rah_flat so that it:

  • recursively processes directories
  • uses a folder based matching pattern where the directory name is then used for getTemplateType().
  • (and ideally make rah_flat backwards compatible to the normal method for those legacy projects)

But you would still have the problem of possible duplicate form names. That would require either that:

  • Textpattern tolerates forms with the same form name but different types and if it does, also knows which of them to output when you put it in a form="my-form" attribute. You could try that out. If it doesn’t you’d need a mechanism for letting txp know which form is which, which would affect lots of txp tags. If that’s the case, IMHO, a naming convention would be easier than specifying another formtype attribute.
  • rah_flat filters out duplicates. In rah_flat you’d need to have a policy for which would be kept or dropped (first come first served, last one overwrites), and rah_flat would need to report it in the tag trace (not visible enough?) or as an error (too visible?), or you wouldn’t know why it’s not working.

That isn’t a problem if you use the directory name as the form prefix, as in my last post. The problem there would be exceeding the max number of characters.

BTW: I’m not trying to shoot this down – I think it’s a good idea too – just thinking it through.

BTW II: My initial idea with a task runner could still work without modifying txp or rah_flat.


TXP Builders – finely-crafted code, design and txp

Offline

#16 2016-02-04 21:31:58

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
Website

Re: rah_flat (template file extensions)

So jakob, dod you know enough php to change the routine that looks in the flat folders so that it works recursively?

That’s really all I want.

Offline

#17 2016-02-05 09:18:41

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,453
Website GitHub

Re: rah_flat (template file extensions)

mrdale wrote #297728:

For now I use all forms as .misc because form types are functionally irrelevant.

Forms of type article still have relevance on the Write panel, but if you’re not using override forms then, yes, types are for organisation only.

jakob wrote #297733:

you could theoretically use anything if txp doesn’t mind.

Unfortunately Txp minds (at present). From 4.6.0 though, there’s a new function get_form_types() which responds to the event>step form.types>types so plugins can extend or alter them. The Forms panel doesn’t use it right now, but alterations to a couple of lines of code would probably change that. Been meaning to try that for ages so I shall test it prior to release.

As I’ve mentioned before I’ve flip-flopped so many times on allowing arbitrary Form types. It’s not technically difficult to do behind the scenes, it’s just making a usable interface that I always struggle with. Always ends up being clunky or unintuitive, or causes workflow inconsistencies due to the “essential” Forms and multi-edit tool. There are threads about my plight dotted around the forum if anyone wishes to put me out of my misery and suggest a way to do it.

But you would still have the problem of possible duplicate form names.

That’s the killer point. The database index is on the name only so they have to be unique across types. myform.misc and myform.section will break things. Any third party such as this plugin would need to enforce uniqueness.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#18 2016-02-06 13:09:00

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,729
Website

Re: rah_flat (template file extensions)

mrdale wrote #297740:

do you know enough php to change the routine that looks in the flat folders so that it works recursively?

I’ll have a go – no guarantees though. I can’t code like Jukka and I can’t do it right away either, but I’m interested in the idea too…


TXP Builders – finely-crafted code, design and txp

Offline

#19 2016-02-29 01:36:47

giz
Member
From: New Zealand
Registered: 2004-07-26
Posts: 301
Website GitHub Twitter

Re: rah_flat (template file extensions)

I’m trying to wean myself off cnk_versioning and move to rah_flat.

The problem is, I can never get rah_flat to work. If my assigned template directory is empty, no errors. The moment I add my ‘default.txp’ file into templates/pages/, I get General error Textpattern Error: Table 'txp_page' was not locked with LOCK TABLES errors, both in admin and on the site.

This happens on a fresh install as well as installing rah_flat on an ex-cnk_versioning site.

Any suggestions?

Offline

#20 2016-02-29 07:21:13

bici
Member
From: vancouver
Registered: 2004-02-24
Posts: 2,092
Website Mastodon

Re: rah_flat (template file extensions)

giz wrote #298056:

I’m trying to wean myself off cnk_versioning and move to rah_flat.

The problem is, I can never get rah_flat to work. If my assigned template directory is empty, no errors. The moment I add my ‘default.txp’ file into templates/pages/, I get General error Textpattern Error: Table 'txp_page' was not locked with LOCK TABLES errors, both in admin and on the site.

This happens on a fresh install as well as installing rah_flat on an ex-cnk_versioning site.

Any suggestions?

man this inability to have an elegant simple solution to flat files is soooo 2005


…. texted postive

Offline

#21 2016-02-29 11:21:29

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: rah_flat (template file extensions)

bici wrote #298058:

man this inability to have an elegant simple solution to flat files is soooo 2005

It’s already in a branch awaiting Textpattern 4.7. Please be patient.

Offline

#22 2016-02-29 20:19:05

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,729
Website

Re: rah_flat (template file extensions)

giz wrote #298056:

The moment I add my ‘default.txp’ file into templates/pages/, I get General error Textpattern Error: Table 'txp_page' was not locked with LOCK TABLES errors, both in admin and on the site.

I’ve never seen that before, so I’m not really sure why. Maybe something special with your mysql setup?

A long shot. Jukka’s last commit removed a lock tables command – see here. You might want to see if reinstating those two lines correct things for you. If you didn’t install with composer and are not sure where those are in the plugin code, click on the ‘concertina’ icons in the line numbers on github to reveal the preceding and following code.

Otherwise, I’ve found it does work as a more reliable replacement for cnk_versioning.


TXP Builders – finely-crafted code, design and txp

Offline

#23 2016-02-29 20:58:15

giz
Member
From: New Zealand
Registered: 2004-07-26
Posts: 301
Website GitHub Twitter

Re: rah_flat (template file extensions)

jakob wrote #298075:

A long shot. Jukka’s last commit removed a lock tables command – see here.

Thanks Juilian – your long shot did the trick – I removed the safe_query lines on either side of the callback_event and all is well :)

Last edited by giz (2016-02-29 20:58:28)

Offline

#24 2016-03-01 08:30:07

Algaris
Member
From: England
Registered: 2006-01-27
Posts: 553

Re: rah_flat (template file extensions)

bici wrote #298058:

man this inability to have an elegant simple solution to flat files is soooo 2005

philwareham wrote #298060:

It’s already in a branch awaiting Textpattern 4.7. Please be patient.

Whoop! Whoop!

Last edited by Algaris (2016-03-01 08:30:54)

Offline

Board footer

Powered by FluxBB