Jump to content

Search the Community

Showing results for tags 'Page Functions'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to ProcessWire
    • News & Announcements
    • Showcase
    • Wishlist & Roadmap
  • Community Support
    • Getting Started
    • Tutorials
    • FAQs
    • General Support
    • API & Templates
    • Modules/Plugins
    • Themes and Profiles
    • Multi-Language Support
    • Security
    • Jobs
  • Off Topic
    • Pub
    • Dev Talk

Product Groups

  • Form Builder
  • ProFields
  • ProCache
  • ProMailer
  • Login Register Pro
  • ProDrafts
  • ListerPro
  • ProDevTools
  • Likes
  • Custom Development

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests

Found 1 result

  1. Hello, as an example imagine this structure: Templates: CarManufacturerTemplate Name: String CarTemplate Name: String Owner: String CarManufacturer: Page(where Template == CarManufacturerTemplate) Pages: CarManufacturers Manufacturer 1 [Template = CarManufacturerTemplate] Name = "Toyota" Manufacturer 2 [Template = CarManufacturerTemplate] Name = "Ford" Cars Car 1 [Template = CarTemplate] Name = "Car 1" Owner = "Steve" CarManufacturer = Manufacturer 1 (Shown as "Toyota") Car 2 [Template = CarTemplate] Name = "Car 2" Owner = "Bob" CarManufacturer = Manufacturer 1 (Shown as "Toyota") Car 3 [Template = CarTemplate] Name = "Car 3" Owner = "Jack" CarManufacturer = Manufacturer 2 (Shown as "Ford") So there are multiple manufacturers, multiple cars, and every car has a reference to its manufacturer. On the page mysite/cars/car-1/ I want to be able to present the data in a manufacturer-specific way but without doing something like this: <?php if ($page->CarManufacturer->Name == "Toyota") { //Show Toyota specific formatting } else if ($page->CarManufacturer->Name == "Ford") { //Show Ford specific formatting } ... ?> Instead I want to be able to give every child-page of the CarManufacturers-page some code which takes the required data as parameters and creates the formatted output on its own. This way, whenever I add a new manufacturer, I don't have to go through all the places which output manufacturer-specific data and add another if-statement. Instead I want to be able to write code on a per-manufacturer basis. A possible way of doing this would be a FieldType which allows me to enter PHP code in the backend. I'd add another field to the CarManufacturer-template: Templates: CarManufacturerTemplate Name: String CustomFunctions: MyCustomTypeWhichExecutesPHP And the backend page for Manufacturer 1 (Toyota) looks like this: |------------- | Name: | |-------- | | Toyota | |-------- | CustomFunctions: | |------------------------------------------------------ | | public function OutputCarData($SomeCarData) { | | //Show Toyota specific formatting | | } | |------------------------------------------------------ And in the template-code of CarTemplate I can just do this: <?php $SomeCarData = $page->whatever; $page->CarManufacturer->CustomFunctions->OutputCarData($SomeCarData); ?> And I don't need to change that code at all when I add another car manufacturer. I just type in another function OutputCarData which does the formatting appropriately. I hope there is a simpler way for this than creating a custom FieldType. If you have any further questions feel free to ask and I will try to answer them or provide more details in what I want to achieve. Many thanks, _NameLess_
×
×
  • Create New...