Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End MVC Re-Org – need help with templating / views

  • This topic is empty.
Viewing 6 posts - 16 through 21 (of 21 total)
  • Author
    Posts
  • #183311
    __
    Participant

    if I had hard-coded HTML emails, I should store this among my model correct?

    I’d put them in a config file (or something).

    #183312
    shaneisme
    Participant

    You could separate further again with a database class.

    I do have a parent class that has the core CRUD methods that each individual SQL method will call upon, so at least that’s not repeated.

    I’d put them in a config file (or something).

    I’m going to put the HTML itself into template files, but those will be called from some email views… now I just need to figure out how the hell to organize this… by email… page that called it… hmm…

    #183317
    shaneisme
    Participant

    Now, I might be over-thinking this… but bear with me, this website has a lot of emails.

    1) HTML for emails themselves will be in templates folder.
    2) Location for templates will be in model (?)
    3) Controller passes data to view which will assemble and send the email

    Is #2 just taking things a step too far?

    For #3, should the controller take care of the actual send part?

    #183430
    shaneisme
    Participant

    To answer my own question based on what I’ve put together so far: I’m not doing anything in the model with emails, I’ll just have the view call any templates it needs to output the object.

    I’m also just naming the templates after the email method name so there’s a direct correlation there.

    So now my next quandry… if I’m just doing this:

    ob_start();
    include path/to/file.php
    $body = ob_get_clean();

    I could technically just put the HTML in as a string in the view… am I gaining anything by keeping it in a separate file (other than reusability)?

    #183432
    __
    Participant

    It’s usually easier to write the templates if they’re in a separate file. I have three approaches:

    • separate html+php template, wrapped in an output buffer. This form is easy to write, especially since you don’t strictly need to know how it is included/parsed. I do this when clients or third parties might need to work with the template.
    • separate php template (but no output, so no output buffer needed) which returns a string when included. I like this method best (it feels very “clean” to me), but it’s more fragile in case anyone else needs to handle them, so I don’t get to use this method as often as I’d like.
    • string template written directly in the view class (or similar). I don’t really like this approach because I have to use string replacement (and/or wrap it in a function). I try not to do this except as a “fallback” template, or for really short strings.
    #183436
    shaneisme
    Participant

    OK – I think I’ll keep doing it inside the buffer, I’m going to be passing this project off to another team eventually. The easier things are to be reused, or edited, the better.

Viewing 6 posts - 16 through 21 (of 21 total)
  • The forum ‘Back End’ is closed to new topics and replies.