Peter Falkenberg Brown Posted March 28, 2013 Share Posted March 28, 2013 Hi Folks, MODX has a nifty feature that allows one to create an article, and then switch templates, in a dropdown, much like PW's, to a different template. There is one distince difference however: the MODX templates are simply read-only presentations of that data record. When I experimented with PW yesterday, and switched the dropdown template on a "writers" page, which had some "writers" fields attached, PW warned me that the data would be deleted. I went ahead, to see what would happen, and then examined the tables in MySQL. I noted that the rows for that "writer" were deleted, but that the select_writer_id row was not deleted. It seemed to be an orphan. More importantly however, it highlighted the fact (as I perceive it) that PW's "template" is actually a "virtual row" for one data record, assembling all of the fields. That's ok, but it also creates a "locked in" system, where the template is no longer just a read only way of presenting data, but is also a data dictionary method of storing data. In addition, the page of that virtual data record can't be displayed at that url, unless a template *file* that corresponds to that internal template name exists on disk. This creates the situation where one might create a data record, i.e. page, and then decide to use a different template for one particular page. However, switching templates for that page destroys the data for that record. I'm probably missing something, but it seems to me that PW should have *two* fields: - data_record_definition (i.e. fulfilling the function of the internal template "virtual row") - external_template (used for presenation on the web, to present the data) Then, one could easily switch the external template, without affecting the internal template's data row definition. I'm a little stuck, at this point, on this, because it seems that once you commit to a particular template, you are indeed committed, or stuck (take your pick). I think I saw something about cloning templates, but then you have the problem that if you add a new field to the 1st tempate, the 2nd template is incomplete. (If I saw that correctly.) Thanks for everyone's feedback. Peter Link to comment Share on other sites More sharing options...
WillyC Posted March 28, 2013 Share Posted March 28, 2013 you.do what u want with tamplate.file include("./somefileother.php"); include("./views/{$page->youview}.php"); also you enjoy: edit.tamplete --> advanceded --> altrenate tamplate filenames Link to comment Share on other sites More sharing options...
Soma Posted March 28, 2013 Share Posted March 28, 2013 "Template" inPW is like a db table with all its fields. If you change the structure of the table you loose data... Except for fields that are the same in the template you change to. Changing a template of a page is not something you do all the time and only to give this page a different content or meaning. It's all about data here and not presentation. "Template File" is more of what you think of in MODX I think, and it's linked to the Template by it's filename. But you don't have to create a file for a template unless you want or need to have it renderable or viewable. The Template name also can be changed, thus mapping it to a different template file. As WillyC pointed out you can also leave the name (which often is used in template code as indentifier and you don't want to change that, unless developing) and define a alternative name that will be used to map to a template file. You can even have all your template share the same template file simply by setting this. A page using a template to build it's data model also isn't locked in to a certain presentation. You can change your presentation template on runtime or have some MVC like approach even. You could even build a simple system to be able to select from different "presentation modes" on a page using page field to build a selection. You make it up. There's many possibilities with how Template and Template Files work together and it allows for some great flexibility in a simple manner. I even after some time working with PW I found ways I didn't see or knew it was possible before, so enjoy the ride. Not sure this is of any help. Always struggle a little explaining this stuff. 1 Link to comment Share on other sites More sharing options...
Soma Posted March 28, 2013 Share Posted March 28, 2013 Edit: Wanted to add something I forgot. You can also enable davanced mode (config.php) and you'll have a select underneath the fieldgroup on the template edit screen to select a Fieldgroup from another Template. It will reference the fieldgroup of that template and and stay connected that if you change the original it will reflect on the template that share the same fieldgroup. This could also be used (instead of cloning) to have different templates having same data type but have a different name thus a different template file. BTW the whole admin backend is done using one template 'admin' using processes you define on a admin page to tell what functionality or controller it has. 1 Link to comment Share on other sites More sharing options...
Peter Falkenberg Brown Posted March 29, 2013 Author Share Posted March 29, 2013 Dear WillyC and Soma, Thanks for your answers! I really appreciate it. Peter Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now