Skip to content

Structure theme's app dir more like Rails #26

@mallorydxw

Description

@mallorydxw

rails-template:

% tree app
app
├── assets
│   ├── config
│   │   └── manifest.js
│   ├── images
│   ├── javascripts
│   │   ├── application.js
│   │   ├── cable.js
│   │   ├── channels
│   │   └── google_analytics.js.coffee
│   └── stylesheets
│       ├── 1st_load_framework.css.scss
│       └── application.css.scss
├── channels
│   └── application_cable
│       ├── channel.rb
│       └── connection.rb
├── controllers
│   ├── application_controller.rb
│   ├── concerns
│   └── visitors_controller.rb
├── helpers
│   └── application_helper.rb
├── jobs
│   └── application_job.rb
├── mailers
│   └── application_mailer.rb
├── models
│   ├── application_record.rb
│   └── concerns
└── views
    ├── layouts
    │   ├── application.html.haml
    │   ├── mailer.html.erb
    │   ├── mailer.text.erb
    │   ├── _messages.html.haml
    │   ├── _navigation.html.haml
    │   └── _navigation_links.html.erb
    ├── pages
    │   └── about.html.erb
    └── visitors
        └── index.html.erb

The "model" component tends to come from WordPress itself. But it might be useful to create our own models. i.e. if your site has a "Report" post type, have a Report class that's a subclass of the \WP_Post class, and includes static methods like ::query_posts() and ::get_post() - which then returns an array of Reports. (If this makes sense to do it should be a separate library - and there may already be a library like that out there). We could then pass that Report object into the Twig template.

We should be able to put WordPress's templates (templates/ currently) and Timber/Twig's templates into app/views/. Not sure how they could be divided though. But could we get rid of the templates/ directory as it currently exists and move that functionality into classes that then load a particular Twig view?

Do we have anything resembling a "controller" in WordPress land? 🤷‍♀️

And we could potentially have a directory reserved just for adding hooks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions