We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 51038
    • 9 Posts
    Hi - let me preface this by saying that I'm entirely new to website building (though I've messed about with some object-oriented bits of code before, in a rather desultory way). I decided to use MODX revolution for my first attempt because it didn't ram a generic template down my throat. I don't mind looking things up a lot, but it's quite likely that I'm going to be asking for explanations of the bleedin' obvious.

    Anyway, THE PROBLEM: I want to add a custom background from a jpeg file to the custom template I'm making, so that it appears on all pages. I've imported a file called "paper.jpg" into the custom folder "assets/components/images" and (using HTML) I've added (amongst other things):

    <body background="paper.jpg"> [[*content]] </body>

    How do I get the HTML reference to call on the jpeg I've imported?

    Thanks for your patience!

    This question has been answered by sottwell. See the first response.

    • Learn about HTML and CSS. Set your colors, fonts, backgrounds and background images in the CSS.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
      • discuss.answer
        Your CSS would look like this, with the url(...) being the relative path to the image file.
        body {
          background: url(paper.jpg);
        }
        


        I would recommend these, or just do a Google search for tutorials.
        http://abookapart.com/products/html5-for-web-designers
        http://abookapart.com/products/css3-for-web-designers

        http://www.w3schools.com/html/default.asp
        http://www.w3schools.com/css/default.asp
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 51038
          • 9 Posts
          Gosh, that was very quick - thank you. Okay, I need to use CSS for backgrounds. And remember to put the whole file path in when I'm using imported assets ... [ed. note: filcher last edited this post 8 years, 8 months ago.]
          • Here's a couple of other interesting ways to handle images in CSS
            https://css-tricks.com/css-sprites/
            https://css-tricks.com/data-uris/
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 51038
              • 9 Posts
              Thanks again - I appreciate your time.
                • 46886
                • 1,154 Posts
                Hi, I was where you are not long ago. It takes time but not that much time to figure out the basics. Hope I could jump in here.

                I am going to make some examples but none of it is working code. If you can ask a very specific question then this forum can and will provide you with working code, but at this stage I hope I could help in a broader way.

                Keep in mind there are always many ways to skin a cat, if that's what you are after.

                The problem with the code you wanted to use is that while you are right to connect the pic with the <body> element, the [*content] is only going to be one resource's content. Also, the pic is connected to the <body> element in css, so its possible you could have it anywhere within the body tags and it would still apply. Css can make things move around to some extent.

                Remember now you are talking about the template not the resource contents.

                Usually you will have something like the following in your html:

                <html>

                <head>

                This is where you must do some important things, including connecting with your css file and setting the path to your installation. If this is set right then your picture link is relative, ie /images/coolpic.jpg. Setting the path says that the system knows that the site is www.coolpics.com and so can attach that to the front of the picture path above. The code for the path is relatively simple if your install isn't a custom job, I use <base href="[[++site_url]]" /> and also this will help your site be better for search <title>[[++site_name]] - [[*longtitle]]</title>

                </head>

                <body>

                Normally you would put your html here with the pic you wanted, but I think Susan's css code is all you need! There is, I believe, no html image element involved at all, as the css connects the <body> element with the pic.

                Note that this code goes in the css file not in the template! It is possible to put most or even all css into the html itself, but...it would make the work harder. Split them up, call to the css up in the <head> section, and then its much easier. In css, first its the selector (like <body> or by class or id), and then the styling, including color, size, position, the works.

                <header>

                Here is where you can put your top pic if you want to, or some navigation, both of these will be html with css for styling and placement. Navigation can also go farther down, and again css controls its location as much as if not more than the html.

                Stuff like the navigation can be cut out later and put into a chunk, that makes the template easy to read and helps when you want to control some changes across multiple templates.

                </header>

                <section>

                Ok I am going to have 2 sections, first one will have my [*content] element, which means the contents of each individual page.

                But if I want to I can have a navigation in here too, and use some code like float:left to push it out of the way, to one side or above of below, of the contents. It might matter if the html of a nav is right before or after the content call, but still you got control.

                </section>

                <section>

                This section is for something else, navigation, some tools to give other contents, maybe just my flickr stream. There are a lot of tools and methods once you know what you want.

                </section>

                <footer>

                There are some traditional elements you can consider for this space. Copyright coolpics.com

                </footer>

                </body>

                </html>

                HTH and feel free to ask questions!
                • You forgot perhaps one of the most important parts of any HTML template - the doctype. This tells the browser what version of HTML to use. Not having a doctype puts the browser in what is called "quirks mode", where your layout will be at the mercy of whatever quirks any give browser may have. So the very first line in any HTML template should be
                  <!doctype html>

                  This will tell the browser to render the page according to HTML 5 standards.
                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                    • 51038
                    • 9 Posts
                    Thanks, Nuan88. Now that I've got my front end more or less the way I want it, I'll take your advice and tidy everything up in a more coherent and efficient way than the ad hoc way I've been messing around so far.
                      • 13226
                      • 953 Posts
                      @Filcher

                      How good is your understanding of HTML + CSS ?

                      I've stepped on peoples feet in this forum before and don't like doing it - looking at the code above, there is huge room for discussion.

                      If your knowledge is very limited, if I may, I would suggest you build a basic <div> based template without using HTML5 tags.

                      The reason - simply the proper understanding of the elements and their use.

                      Please note: I am not perfect and I don't know everything about HTML + CSS, the following is just one example from a multitude of possibilities when it comes to layout and styling.

                      An example:

                      "Footer" & "Header" tags are not document specific, they can be used in a variety of other elements and numerous times

                      A very basic HTML5 template:
                      <!DOCTYPE HTML>
                      <html>
                      <head>
                      <meta charset="utf-8">
                      <title>Page Title</title>
                      </head>
                      <body>
                      <header>
                        <h1>Logo</h1>
                        <nav>Link List here</nav>
                      </header>
                      <main>Content</main>
                      <aside>Sidebar</aside>
                      <footer>Document Footer</footer>
                      </body>
                      </html>

                      Basic HTML5 template with an article in the main content area which uses header + footer tags:
                      <!DOCTYPE HTML>
                      <html>
                      <head>
                      <meta charset="utf-8">
                      <title>Page Title</title>
                      </head>
                      <body>
                      <header>
                        <h1>Logo</h1>
                        <nav>Link List here</nav>
                      </header>
                      <main> 
                        <!-- Start Content -->
                        <article>
                          <header>
                            <h2>Article header</h2>
                            <p>short intro text / subline etc.</p>
                          </header>
                          <p>Article content in a normal paragraph</p>
                          <footer>Info about the article writer</footer>
                        </article>
                        <!-- / End Content --> 
                      </main>
                      <aside>Sidebar</aside>
                      <footer>Document Footer</footer>
                      </body>
                      </html>

                      At this stage simply styling up the "header" or "footer" tags could cause problems, as one header is the document header and the other an article header - both probably should look completely different - same goes for the footer.

                      To get around this problem (in this specific situation) you could use "IDs" or "classes" or even "aria roles" which help make the page more accessible and at the same time you can be more specific with your CSS styling, by addressing the roles.

                      Basic template using role:
                      <!DOCTYPE HTML>
                      <html>
                      <head>
                      <meta charset="utf-8">
                      <title>Page Title</title>
                      </head>
                      <body>
                      <header role="banner">
                        <h1>Logo</h1>
                        <nav>Link List here</nav>
                      </header>
                      <main role="main">Content</main>
                      <aside role="complementary">Sidebar</aside>
                      <footer role="contentinfo">Document Footer</footer>
                      </body>
                      </html>

                      Possible styling model - using attribute selectors:
                      main[role=main]{}
                      header[role=banner]{}
                      header[role=banner] h1{}
                      header[role=banner] nav{}
                      main[role=main]{}
                      aside[role=complementary]{}
                      footer[role=contentinfo]{}

                      There are now more options available to you, examples:

                      Generalise header & footer then override using the role element
                      header{}
                      footer{}
                      main[role=main]{}
                      header[role=banner]{}
                      header[role=banner] h1{}
                      header[role=banner] nav{}
                      main[role=main]{}
                      aside[role=complementary]{}
                      footer[role=contentinfo]{}

                      Using the parent element you can specify the child elements
                      main[role=main]{}
                      header[role=banner]{}
                      header[role=banner] h1{}
                      header[role=banner] nav{}
                      main[role=main]{}
                      main[role=main] header{}
                      main[role=main] footer{}
                      aside[role=complementary]{}
                      footer[role=contentinfo]{}

                      Even more specific:
                      main[role=main]{}
                      header[role=banner]{}
                      header[role=banner] h1{}
                      header[role=banner] nav{}
                      main[role=main]{}
                      main[role=main] article header{}
                      main[role=main] article footer{}
                      aside[role=complementary]{}
                      footer[role=contentinfo]{}

                      The CSS can go further by generalising and overriding in each section etc.

                      This is all open for discussion, some will say it's wrong, others will agree with what I have written - at the end of the day, as a beginner I wouldn't jump in at the deep end without a vest.

                      Simply create a basic "div" based template and add your elements to it, example:
                      <!DOCTYPE HTML>
                      <html>
                      <head>
                      <meta charset="utf-8">
                      <title>Page Title</title>
                      </head>
                      <body>
                      <div id="header">
                        <h1>Logo</h1>
                        <div class="nav">Link List here</div>
                      </div>
                      <div id="content">Content</div>
                      <div id="sidebar">Sidebar</div>
                      <div id="footer">Footer</div>
                      </body>
                      </html>

                      I've created a couple of the examples above and attached them to this post - feel free to download the zip if the interest is there. [ed. note: iusemodx last edited this post 8 years, 8 months ago.]