Skip to main content

Forums

  • This topic is empty.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #194106
    bearhead
    Participant

    Hey, this isn’t a js question per se, so I put it in this forum.

    I’m working on a website for my engineering firm that has over 300 separate pages for their projects. In order to improve maintainability, I created one “template” page for all the projects. That template gets included via php on to a projects file’s index.html page, and then content is inserted in via javascript.

    It is kind of convoluted, but the benefit is that if my boss wants something changed that requires editing html, I only need to do it once to the template document and not 300 times to each project file.

    However, this make the site pretty much totally dependent upon javascript… is that smart? Should I be going about it in a different way? Is there an equivelent to this script: $(".quote").load("project_data.html #quote"); in php I could use?

    here is an example project so you can see what I have going on: http://www.aeieng.com/new_aei/project1/

    #194122
    Shikkediel
    Participant

    This answer on Stackoverflow looks like a php alternative :

    http://stackoverflow.com/a/9539996/3168107

    And yes, it’s probably a better approach then loading everything with JavaScript. If only for general search engine indexing…

    #194342
    bearhead
    Participant

    This reply has been reported for inappropriate content.

    hmm… maybe I missed something on that link, but it looks like it only demonstrates some methods of inserting a whole document via php.

    What I need to do is take the content from specific divs on one document, and then insert it into other specific divs in another document.

    #194343
    Paulie_D
    Moderator

    What I need to do is take the content from specific divs on one document, and then insert it into other specific divs in another document.

    Ugh…

    The answer Shikkediel gave was specifically stated to be a PHP alternative which is designed to use templates like that.

    It’s gotta be a much better option that this “cloning” or “cut and pasting”.

    #194344
    nkrisc
    Participant

    This reply has been reported for inappropriate content.

    Sounds like you might consider using a CMS of some sort.

    #194345
    Shikkediel
    Participant

    If the original HTML files should be kept as they are, it’s probably preferable to use file_get_contents so the data can be ‘hacked up’. To be able to discern the elements from each other, we come into an area I know little about – one would need a regex or parser library.

    Were the job up to me, I’d make smaller templates of the original files and insert them separately into the document – with the readfile method or include with echoed HTML even.

    Edit – also in response to nkrisc, I think this is a basic CMS of sorts…

    #194359
    bearhead
    Participant

    This reply has been reported for inappropriate content.

    @Paulie_D

    Sorry, I don’t quite follow you. I can include the template through php, but how then do I get each project’s unique content into it? I still need javascript or php to move the content into the divs they belong in, right? or am I missing something?

    @Shikkediel
    Yeah, I currently have something almost working with file_get_contents. But the problem with that is that I can’t figure out how to preserve my <a href=""></a> links – its just converting everything into a text string.

    Using a separate php file for each section of the page will work – though I would say it is my last resort… I’ll end up with maybe a dozen php files for each project, so creating all of them for 300 or so projects will be an exercise in monotony to say the least ;)

    edit:
    I got the functionality I was looking for by using this php:
    ”'<?php
    $content = file_get_contents(‘project_data.html’);
    $first_step = explode( ‘

    ‘ , $content );
    $second_step = explode(“

    ” , $first_step[1] );
    echo $second_step[0];
    ?>”’

    #194381
    chrisburton
    Participant

    This reply has been reported for inappropriate content.

    Using a separate php file for each section of the page will work – though I would say it is my last resort… I’ll end up with maybe a dozen php files for each project, so creating all of them for 300 or so projects will be an exercise in monotony to say the least ;)

    That is why it would be beneficial to use a CMS or a templating framework. Personally, I wouldn’t go with a bunch of includes as you’ll probably just end up doing a lot of copy pasting the same functionality. As you can tell, that’s not very efficient especially if you have access to the content.

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.
icon-link icon-logo-star icon-search icon-star