问题描述:

I'm using the PHP.Gt framework, and I've noticed there's a pagetool for a Blog. I'm sure it's really easy to wire-up (everything else is in PHP.GT!), but I need to know what IDs and data-templates I should set in my html in order for the PageTool to render the blog for me.

I'd rather not step through the code looking for them if I can possibly avoid it, and I can't find the Blog tool in the docs on github - is it documented elsewhere?

网友答案:

Tutorial #4 on the Github wiki will, once written, answer your questions exactly. There is also a specific page within the docs just for the Blog PageTool. While the docs are a WIP, I will use the source and comments to answer here.

You need to do two things to output a typical blog automatically:

  1. Create the markup of a dummy blog within an element with a data-template attribute. This will be placed into the /Blog/_Dynamic.html PageView.
  2. Call the go function on the Blog PageTool.

The database will be deployed automatically when needed. You will then be able to write articles and style the blog using CSS/SCSS.

To answer your question more specifically:

The root element can be any tag type with the template name of "Article". It would make sense for this tag to be an article element.

Within the article element, you can place as much or as little as you require for the type of blog you want to create. The following elements are the most typical:

  • article > header > h1 > a - The title of the article that will provide a permalink back to itself.
  • article > header > p.date - The date of publication, with optional data-format attribute for providing the PHP date format string.
  • article > header > p.comments - The comment count.
  • article > header > ul.tags - The list container for the current tags associated to the article.
  • article > header > ul.tags li[data-template='ArticleTagLink'] - A templated list item that is output for each associated tag. The li should contain at least an a element, to link to the tag list.
  • article > div.content - Where the actual blog content will be output to.

Comments can be placed in a different element container. Within the container, the actual list to output comments to should have an id of "commentsList", with an li element with the data-template attribute of "Comment".

Here is an example blog PageView (_Dynamic.html).

<section id="st_article">
    <article data-template="Article">
        <header>
            <h1>
                <a href="/Articles/{Y}/{M}/{D}/{Id}-{Title}.html">
                    Article header goes here. A bit longer title so it breaks onto 
                    the line below the current one.
                </a>
            </h1>
            <p class="date">
                <time datetime="1970-01-01">1st January 1970</time>
            </p>
            <p class="comments">
                <a href="/Articles/{Y}/{M}/{D}/{ID}-{Title}.html#Comments">
                    <span class="commentCount">0</span> comments
                </a>
            </p>
            <ul class="tags">
                <li data-template="ArticleTagLink">
                    <a href="/Articles/Tagged/{TagName}">Tag1</a>
                </li>
            </ul>
        </header>
        <div class="content">
            <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
        </div>
        <footer>
            <p>
                <a href="/Articles/{Y}/{M}/{D}/{Id}-{Title}.html">
                    Continue reading...
                </a>
            </p>
        </footer>
    </article>
</section>

<a name="Comments"></a>

<section id="st_article_comments">
    <h1><span id="commentCount">0</span> comments</h1>
    <form method="post" id="postCommentForm">
        <input name="Name" placeholder="Your name" required>
        <input name="Website"
            placeholder="Your website">
        <input name="Email" class="email"
            placeholder="Your email (not shown, used to receive replies)">
        <textarea name="Comment" placeholder="Your comment" required
        ></textarea>
        <button type="submit" id="btn_submitComment">
            Submit comment
        </button>
    </form>
    <div id="signIn">
        <p>
            Please 
            <a href="/Authenticate.html">sign in</a> 
            to post a comment.
        </p>
    </div>
    <ul id="commentsList">
        <li data-template-no="Comment">
            <p class="name">
                <a name="Comment-" href="#Comment-">
                    John Smith
                </a>
            </p>
            <p class="message">
                Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
                tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.
            </p>
            <time datetime="1970-01-01 00:00:00">
                January 1st 1970, 0:00am
            </time>
        </li>
    </ul>
</section>

... and to automatically hook the PageView up with the blog tool, you need to call go() on the Blog PageTool. This will have to be done in the _Common.php file, as the actual requested URL for each blog will be different.

<?php class _Common extends PageCode {

public function go($api, $dom, $template, $tool) {
    $tool->go("Blog");
}

}?>
相关阅读:
Top