ThinkPHP3.1快速入门(15)模板布局

ThinkPHP的模板引擎内置了布局模板功能支持,可以方便的实现模板布局以及布局嵌套功能。
有三种布局模板的支持方式:

第一种方式:全局配置方式

这种方式仅需在项目配置文件中添加相关的布局模板配置,就可以简单实现模板布局功能,比较适用于全站使用相同布局的情况,需要配置开启LAYOUT_ON参数(默认不开启),并且设置布局入口文件名LAYOUT_NAME(默认为layout)。

‘LAYOUT_ON’=>true,
‘LAYOUT_NAME’=>’layout’,

开启LAYOUT_ON后,我们的模板渲染流程就有所变化,例如:

Class UserAction extends Action {
    Public function add() {
        $this->display(‘add’);
    }
}

在不开启LAYOUT_ON布局模板之前,会直接渲染Tpl/User/add.html模板文件,开启之后,首先会渲染Tpl/layout.html模板,布局模板的写法和其他模板的写法类似,本身也可以支持所有的模板标签以及包含文件,区别在于有一个特定的输出替换变量{__CONTENT__},例如,下面是一个典型的layout.html模板的写法:

<include file=”Public:header” />
{__CONTENT__}
<include file=”Public:footer” />

读取layout模板之后,会再解析User/add.html模板文件,并把解析后的内容替换到layout布局模板文件的{__CONTENT__}特定字符串。
当然可以通过设置来改变这个特定的替换字符串,例如:

‘TMPL_LAYOUT_ITEM’      =>  ‘{__REPLACE__}’

但是一个布局模板同时只能有一个特定替换字符串。
采用这种布局方式的情况下,一旦User/add.html模板文件或者layout.html布局模板文件发生修改,都会导致模板重新编译。
如果需要指定其他位置的布局模板,可以使用:

‘LAYOUT_NAME’=>’Layout/layoutname’,

就表示采用Tpl/Layout/layoutname.html作为布局模板。

如果某些页面不需要使用布局模板功能,可以在模板文件开头加上{__NOLAYOUT__}字符串。
如果上面的User/add.html模板文件里面包含有{__NOLAYOUT__},则即使当前开启布局模板,也不会进行布局模板解析。

第二种方式:模板标签方式

这种布局模板不需要在配置文件中设置任何参数,也不需要开启LAYOUT_ON,直接在模板文件中指定布局模板即可,相关的布局模板调整也在模板中进行。
以前面的输出模板为例,这种方式的入口还是在User/add.html模板,但是我们可以修改下add模板文件的内容,在头部增加下面的布局标签(记得首先关闭前面的LAYOUT_ON设置,否则可能出现布局循环):

<layout name=”layout” />

表示当前模板文件需要使用layout.html布局模板文件,而布局模板文件的写法和上面第一种方式是一样的。当渲染User/add.html模板文件的时候,如果读取到layout标签,则会把当前模板的解析内容替换到layout布局模板的{__CONTENT__}特定字符串。
一个模板文件中只能使用一个布局模板,如果模板文件中没有使用任何layout标签则表示当前模板不使用任何布局。
如果需要使用其他的布局模板,可以改变layout的name属性,例如:

<layout name=”newlayout” />

还可以在layout标签里面指定要替换的特定字符串:

<layout name=”Layout/newlayout”  replace=”{__REPLACE__}” />

由于所有include标签引入的文件都支持layout标签,所以,我们可以借助layout标签和include标签相结合的方式实现布局模板的嵌套。例如,上面的例子

<include file=”Public:header” />
<div id=”main” class=”main” >
{__CONTENT__}
</div>
<include file=”Public:footer” /> 

在引入的header和footer模板文件中也可以添加layout标签,例如header模板文件的开头添加如下标签:

<layout name=”menu” />

这样就实现了在头部模板中引用了menu布局模板。
也可以采用两种布局方式的结合,可以实现更加复杂的模板布局以及嵌套功能。

第三种方式:使用layout控制模板布局

使用内置的layout方法可以更灵活的在程序中控制模板输出的布局功能,尤其适用于局部需要布局或者关闭布局的情况,这种方式也不需要在配置文件中开启LAYOUT_ON。例如:

Class UserAction extends Action {
    Public function add() {
        layout(true);
        $this->display(‘add’);
    }
}

表示当前的模板输出启用了布局模板,并且采用默认的layout布局模板。
如果当前输出需要使用不同的布局模板,可以动态的指定布局模板名称,例如:

Class UserAction extends Action {
    Public function add() {
        layout(‘Layout/newlayout’);
        $this->display(‘add’);
    }
}

或者使用layout方法动态关闭当前模板的布局功能(这种用法可以配合第一种布局方式,例如全局配置已经开启了布局,可以在某个页面单独关闭):

Class UserAction extends Action {
    Public function add() {
        layout(false); // 临时关闭当前模板的布局功能
        $this->display(‘add’);
    }
}

总结

三种模板布局方式中,第一种和第三种是在程序中配置实现模板布局,第二种方式则是单纯通过模板标签在模板中使用布局。具体选择什么方式,需要根据项目的实际情况来了。

波比源码 – 精品源码模版分享 | www.bobi11.com
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 本站源码并不保证全部能正常使用,仅供有技术基础的人学习研究,请谨慎下载
8. 如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!

波比源码 » ThinkPHP3.1快速入门(15)模板布局

356 评论

  1. order prograf without prescription prograf 1mg pills ursodiol for sale

  2. order cialis 10mg generic Cialis in usa buy sildenafil 100mg without prescription

  3. buy medroxyprogesterone online cheap generic provera 5mg order periactin pill

  4. buy modafinil 100mg canada pharmacy ivermectin for people

  5. olanzapine 10mg generic diovan 80mg generic buy valsartan without prescription

  6. brand linezolid 600mg casinos online online casino for real cash

  7. buy cialis for sale oral viagra sildenafil ca

  8. purchase flomax generic oral zofran 8mg buy aldactone 25mg

  9. online slots real money stromectol ca provigil 200mg price

  10. order terbinafine 250mg online oral lamisil order amoxicillin 250mg pills

  11. Jouer au casino en ligne sur les sites agréés de jeux d’argent autorisés par la France En France, il vous est impossible d’accéder aux sites des casinos qui ne détiennent pas de licence. De plus, les joueurs français qui jouent sur une plateforme de jeu non homologuée et reconnue par les autorités locales peuvent s’exposer à des sanctions pénales. Enfin, en jouant sur un casino illégal, il va de soi que vous ne pourrez pas vous plaindre auprès des mêmes autorités en cas d’arnaque. Les casinos en ligne connaissent depuis des années une véritable popularité. Toutefois, les gouvernements ne voient pas cela d’un très bon œil. Les raisons de cette interdiction des jeux de hasard en ligne sont assez diverses et dépendent d’un État à l’autre. Alors que certains pays interdisent totalement les jeux d’argent, d’autres tentes d’imposer des réglementations afin de réguler au maximum ce genre de pratiques.
    https://titussyqi321098.vidublog.com/16812118/site-de-poker-en-ligne-gratuit
    Essayez-vous sur Big Bass Bonanza et tentez de gagner le jackpot sur ce slot à 5 rouleaux et 10 lignes de paiement. Avec cette machine à sous, vous avez la possibilité de décrocher des poissons-jackpot et de gagner jusqu’à x2100 votre mise initiale. Le jeu est relativement simple et fun. La stratégie ultime pour gagner aux machines à sous est évidemment liées aux mises. Comme dans tout jeu de casino, jouer rime souvent avec miser. Et à chaque jeu son types de mises. Quelles sont les types de mises et comment miser aux machines à sous? Nous avons consacré un article à cette question dont dépend beaucoup l’optimisation de votre jeu. Dans cet article nous vous parlerons taux de redistribution, choix de la machine à sous, choix des options de jeu, mais aussi lignes de gain …

  12. Kerala Blasters will take on Goa on Sunday, November 13, at Jawaharlal Nehru International Stadium (Kochi, Kerala).If you are looking for KBFC vs FCG Dream11 Fantasy Football Prediction then you are at the right place. #6 Is there a playoff round in Indian Super League after the regular season?There isn’t a playoff competition after the regular season in Indian Super League. Doha: Spain put on a footballing masterclass … M01 | OCT 14, 2022 | Chennaiyin FC 1-1 Bengaluru FC, Match Report Simon Grayson’s side went into the new ISL season on the back of a first Durand Cup title. With fans once again allowed into the stadiums, expectations from the 2018-’19 champions were high. There was a new hope. However, the pre-season buzz has not translated into results on the pitch. There goes the final whistle and East Bengal draw a blank on the Kolkata Derby. ATKMB found the net twice within 10 minutes in the second half, and that is more than enough for them for a memorable night. 
    https://tiny-wiki.win/index.php?title=Mobile_flash_score_soccer_results
    The UEFA word, the UEFA logo and all marks related to UEFA competitions, are protected by trademarks and/or copyright of UEFA. No use for commercial purposes may be made of such trademarks. Use of UEFA.com signifies your agreement to the Terms and Conditions and Privacy Policy. Email address not available. Always keeping abreast of the events in the football world is a task for true fans. With livescores.biz it becomes much easier, because all football today results are published on one site, which will allow you not to miss an interesting event. ©Tue Nov 29 22:44:10 CET 2022 xscores.com All rights reserved. The Women’s ITF World Tennis Tour offers approximately 500 tournaments in over 60 countries worldwide and incorporates five prize money levels of tournaments: 15s – offering $15,000 in prize money; 25s – offering $25,000 in prize money; 60s – offering $60,000 in prize money; 80s – offering $80,000 in prize money; 100s – offering $100,000 in prize money.

  13. buy acetazolamide 250 mg generic imuran ca buy azathioprine 25mg without prescription

  14. generic nortriptyline paxil oral order paroxetine sale

  15. UFC 284 Betting I’m between BetOnline and 5dimes based on feedback so far. BetOnline GUI looks nicer, but I don’t really care that much about it. Copyright © 2023 Penske Business Media. All rights reserved. Horse Racing Betting – Where To Bet on the Horses Of course, to top the list is one of the best sports betting sites and the official sportsbook of the UFC, the DraftKings Sportsbook. This deal (made in 2021) gives DraftKings exclusive rights to particular promotions for UFC events, boosted odds, in-broadcast odds for live betting, and UFC branding and marketing assets for the sports betting platform. DraftKings has been a household name in the US for daily fantasy sports since 2012 and eventually launched one of the country’s biggest sportsbooks betting apps in late 2018 after changes in legislation were made earlier that year.
    https://subscribe.ru/author/30778294
    Put it all together, and I’m excited to grab +100 odds at FanDuel. You can also find +100 odds at BetRivers, but DraftKings and Pointsbet have the over priced out to -110 and -115. Last updated: Feb 7, 2:56 PM UTC We got some NBA player props for you! Eight NBA games are on the program this evening, meaning that there are literally thousands of player props you can bet on. We’re here to help you choose the winning ones with our top three picks for tonight’s games. Clippers vs Nets How to Watch Odds Prop All odds via DraftKings Sportsbook Best NBA Bets Today | NBA Picks February 7 Analyzing Tuesday’s Cincinnati at Tulane odds and lines, with college basketball expert picks, predictions and best bets. Check out our best 76ers vs. Knicks picks based on the top NBA odds. My Pick: Suns at Pistons Over

  16. thesis statement for narrative essay example education thesis thesis statement on global warming

  17. how to buy ezetimibe zetia 10mg cost buy methotrexate cheap

  18. buy ivermectin canada absorica order order isotretinoin 20mg pill

  19. buy ventolin inhalator for sale synthroid brand order synthroid 150mcg without prescription

  20. Welcome to our community!! HTTPS connection ensures that when you insert senstivie data, all the traffic is encrypted. We use dedicated people and clever technology to safeguard our platform. Find out how we combat fake reviews. It’s bigger with foreign links. Dont go the site, do not install anything it tells you. Ignore it and move on to a different link. or wait for it to come out. 419.4K views|Becoming one of “The People” Becoming one with Neytiri – James Horner Which websites compete with the website Slotslights.com on the web? Here are }}}}n} websites are similar to it. Here are }}}}n} links on the homepage of Slotslights.com, including }}}}n} internal links, }}}}n} external links, and }}}}n} other links (eg, Javascript). It’s bigger with foreign links. Dont go the site, do not install anything it tells you. Ignore it and move on to a different link. or wait for it to come out.
    https://old.wol.co.kr/bbs/board.php?bo_table=free&wr_id=96502
    Slot online biasanya amat beraneka ragam, lebih dari 100 tipe permainan slot online ditawarkan oleh lebih dari 10 provider di dunia Ini adalah kunci utama untuk menang di judi slot online. Jika Anda dapat mengendalikan hasrat Anda, itu akan memberi Anda hasil terbaik dalam keadaan apa pun. Dimana jika anda dalam posisi kalah dan bisa berhenti sejenak maka akan mengakibatkan kerugian dengan jumlah yang tidak sedikit, sedangkan anda dalam posisi menang dan akan bisa memaksimalkan taruhan anda secara maksimal sehingga memberikan kemenangan yang maksimal. Slot online biasanya amat beraneka ragam, lebih dari 100 tipe permainan slot online ditawarkan oleh lebih dari 10 provider di dunia Mempunyai visi dan misi menjadi situs slot online terpercaya 2022 tentunya kami mengembangkan teknologi cangih yang mampu diakses melalui smartphone tanpa terkena blokir. Teknologi tersebut bernama AMP (Accelerated Mobile Pages), jadi bagi kalian new member tidak harus khawatir akan terkena blokir oleh pihak berwenang. Pastinya kehadiran teknologi AMP ini mampu mengatasi masalah pemblokiran, jadi kalian dapat bermain secara nyaman dan mempermudah dalam mendapat jackpot. Sebab bermain tanpa hambatan berdampak menghasilkan keuntungan yaitu berupa jackpot slot88 online.

  21. generic tamsulosin 0.2mg order ondansetron order aldactone 100mg pills

  22. buy fluconazole 100mg for sale diflucan 100mg pill buy cipro 500mg online cheap

  23. viagra safe 2 Clinical pregnancy rate; varying indications

  24. Als je aan komt lopen bij Holland Casino Scheveningen word je direct al geïmponeerd door het grootse gebouw. Wanneer je naar binnen loopt kun je via een balie je jas afgeven en vervolgens toegang krijgen langs de kassa’s. De drie coupons zorgen voor extra traffic naar de casinofaciliteiten met bijvoorbeeld de gratis bitterballen als incentive. Online Casino nieuws. Leuke winacties. Nieuwsartikelen over gokken, spelletjes, bingo en bonus. Vul prijsvragen in en speel online geld spelletjes. Speel verantwoord en bewust 18+. Met deze optie plaatsen we enkel functionele cookies. We kunnen jouw gegevens daarom niet gebruiken om onze website te verbeteren. Ook kunnen we je niet voorzien van persoonlijke content of van audiovisuele content van externe (social media) bronnen zoals youtube of soundcloud.
    http://dmonster130.dmonster.kr/bbs/board.php?bo_table=free&wr_id=712935
    Het casino bestaat al sinds 1975 en heeft vele vestigingen door heel Nederland, ook is Holland Casino de enige met het recht om livegames aan te bieden in land based casinos. De missie van Holland Casino is: “ Wij laten mensen veilig, eerlijk en verantwoord genieten van het kansspel en de bijzondere beleving daaromheen. Boven alles willen we een ultieme en unieke gastbeleving realiseren.” Weten ze deze gastvrijheid ook in de online omgeving door te zetten? Ook live wedden is beschikbaar in zowel het casino als sportsbook van Holland Casino. Tijdens sportwedstrijden is er altijd een uitgebreid aanbod waar je op kan wedden tijdens de wedstrijd. Ook daarvoor zit je dus prima op je plek bij Holland Casino. Holland Casino werkt samen met Playtech. Dit bedrijf richt zich al ruim 20 jaar op het ontwikkelen van goksoftware. Buiten sportweddenschappen gaat dit ook om online casino’s, bingo spelen en bijvoorbeeld pokertoernooien. We kunnen daarom wel stellen dat Holland Casino met Playtech een ervaren partner heeft die voor de stabiliteit en een goede structuur zorgt. Al met al een betrouwbare bookmaker dus.

  25. amlodipine 10 norvasc hives high blood pressure medication amlodipine

  26. order avana 100mg online cheap brand diclofenac order diclofenac 50mg online

  27. can lexapro stop working lexapro medscape escitalopram vs escitalopram oxalate

  28. order indomethacin 50mg generic indomethacin ca buy generic suprax for sale

  29. Slots Plus Casino has games, promotions, new games, slots, table games, video poker, specialty games, and live dealer. The site offers a wide variety of the world’s most popular slot games and Table Games, Video poker, Roulette, Craps & Poker. Get the Bonus Bonus valid for new and existing players.Games allowed: Eternal Love.SlotsPlus brings new slots bonus this month, celebrate Valentines Day and more with 25 no deposit free spins, use the bonus code No online casino experience would be complete without generous bonuses and promotions, and SlotsPlus Casino delivers on that front as well. New players can take advantage of a generous welcome bonus that offers up to $10,000 in bonus cash over their first 10 deposits, while existing players can enjoy regular reload bonuses, cashback offers, and more.
    https://uniform-wiki.win/index.php?title=Dice_casino_style
    There are no deposit bonuses in the Philippines of all shapes and sizes. An online casino’s best feature for the player on a budget, no doubt, is a welcome bonus you can claim with zero effort. This page will look at the latest no bonus deposit casino perks for Filipino players for your convenience. Below, you can find a list of the best deals of this variety. Learn more about troubleshooting WordPress. Bonuses are very popular among online casino players, and no deposit bonuses are the closest thing to receiving something for nothing. They appear in the form of credit or free spins, without the player having to deposit any money, as the name suggests. For this reason, we should regard them as a kind of ‘test drive’ of a new casino: we can try out its games and service without committing a deposit.

  30. cialis 40mg pill brand cialis order cialis 20mg pill

  31. ivermectin order online hims ed pills buy prednisone 20mg for sale

  32. vardenafil pills vardenafil usa buy plaquenil tablets

  33. olmesartan 10mg without prescription order benicar pill buy depakote 500mg for sale

  34. com 20 E2 AD 90 20Sa 20Sert 20A 20Quoi 20Le 20Viagra 20 20Viagra 20Bestellen 20Online sa sert a quoi le viagra Pieces of an operation that stretched from Washington, D proscar without a prescription

  35. erythromycin 250mg pill nolvadex price buy tamoxifen paypal

  36. topiramate 100mg uk imitrex 25mg usa buy generic levaquin for sale

  37. If some one desires expert view concerning blogging and site-building then i advise him/her to pay a visit this blog, Keep up the good job.

  38. buy finasteride medication viagra 100mg pills order sildenafil 100mg for sale

  39. pink and blue amoxicillin amoxicillin 500 foods to avoid with amoxicillin

  40. Wonderful website you have here but I was wanting to know if you knew of any community forums that cover the same topics talked about in this article? I’d really love to be a part of online community where I can get feed-back from other knowledgeable individuals that share the same interest. If you have any recommendations, please let me know. Appreciate it!

  41. Hey! I know this is somewhat off topic but I was wondering which blog platform are you using for this site? I’m getting fed up of WordPress because I’ve had issues with hackers and I’m looking at options for another platform. I would be great if you could point me in the direction of a good platform.

  42. Hello, I do believe your web site may be having browser compatibility issues. When I look at your website in Safari, it looks fine but when opening in IE, it has some overlapping issues. I simply wanted to give you a quick heads up! Other than that, fantastic website!

  43. Keep this going please, great job!

  44. non prescription erection pills cheap viagra pill buy viagra 50mg for sale

  45. Wow that was strange. I just wrote an extremely long comment but after I clicked submit my comment didn’t show up. Grrrr… well I’m not writing all that over again. Anyways, just wanted to say great blog!

  46. buy pyridium 200mg generic amantadine usa buy amantadine 100mg online cheap

  47. Heya! I just wanted to ask if you ever have any problems with hackers? My last blog (wordpress) was hacked and I ended up losing months of hard work due to no backup. Do you have any solutions to protect against hackers?

  48. You made some good points there. I looked on the internet to find out more about the issue and found most individuals will go along with your views on this site.

  49. buy avlosulfon pills for sale buy aceon generic perindopril 4mg drug

  50. doxycycline hyclate ivf moa doxycycline doxycycline for gonorrhea and chlamydia

  51. It is perfect time to make a few plans for the longer term and it is time to be happy. I have read this post and if I may just I want to recommend you few fascinating things or advice. Perhaps you could write next articles relating to this article. I wish to read more things approximately it!

  52. hi!,I love your writing so so much! percentage we keep up a correspondence more approximately your post on AOL? I need an expert in this area to unravel my problem. May be that is you! Taking a look forward to peer you.

  53. What’s up, this weekend is nice for me, because this occasion i am reading this wonderful informative article here at my house.

  54. cephalexin what is it used for cephalexin 250 5ml can cephalexin 500mg treat chlamydia

  55. It’s going to be finish of mine day, but before end I am reading this wonderful piece of writing to increase my knowledge.

  56. order ditropan 2.5mg without prescription amitriptyline 50mg canada buy alendronate 35mg without prescription

  57. I needed to thank you for this fantastic read!! I definitely enjoyed every little bit of it. I’ve got you book marked to check out new stuff you post

  58. Hello! Do you use Twitter? I’d like to follow you if that would be ok. I’m definitely enjoying your blog and look forward to new updates.

  59. Although a majority of patients described their pain as worse when they were fatigued, a description often voiced by people with chronic pain, the higher percentage of those with widespread pain who experienced worse pain with after exercise, rest or exposure to cold is similar to those with the specific syndrome of FMS side effects of viagra in older men Alternative drug eruption reference manual including freshly squeezed juice or change your doctor about excedrin migraine

  60. fluvoxamine 100mg cheap luvox 50mg ca order generic cymbalta 20mg

  61. Does your website have a contact page? I’m having a tough time locating it but, I’d like to send you an e-mail. I’ve got some creative ideas for your blog you might be interested in hearing. Either way, great website and I look forward to seeing it improve over time.

  62. My programmer is trying to persuade me to move to .net from PHP. I have always disliked the idea because of the expenses. But he’s tryiong none the less. I’ve been using Movable-type on a variety of websites for about a year and am anxious about switching to another platform. I have heard very good things about blogengine.net. Is there a way I can transfer all my wordpress content into it? Any kind of help would be really appreciated!

  63. I’m impressed, I must say. Rarely do I encounter a blog that’s equally educative and engaging, and let me tell you, you have hit the nail on the head. The issue is something which not enough folks are speaking intelligently about. I am very happy that I stumbled across this in my search for something relating to this.

  64. Link exchange is nothing else but it is simply placing the other person’s weblog link on your page at appropriate place and other person will also do same in favor of you.

  65. I feel this is one of the so much significant information for me. And i’m glad reading your article. However wanna observation on few general things, The site taste is perfect, the articles is in point of fact nice : D. Good activity, cheers

  66. Thanks for sharing your thoughts on %meta_keyword%. Regards

  67. It’s remarkable designed for me to have a web site, which is valuable for my experience. thanks admin

  68. After looking over a few of the blog posts on your web page, I honestly like your way of blogging. I book marked it to my bookmark website list and will be checking back soon. Take a look at my web site as well and let me know what you think.

  69. I’m gone to say to my little brother, that he should also pay a visit this blog on regular basis to take updated from most up-to-date information.

  70. It is perfect time to make some plans for the future and it is time to be happy. I have read this post and if I could I want to suggest you few interesting things or advice. Perhaps you could write next articles referring to this article. I wish to read more things about it!

  71. I simply could not depart your web site prior to suggesting that I extremely enjoyed the standard information a person supply on your visitors? Is going to be back ceaselessly in order to check up on new posts

  72. It’s really a cool and helpful piece of information. I’m glad that you simply shared this helpful info with us. Please stay us informed like this. Thank you for sharing.

  73. What’s up to every body, it’s my first visit of this weblog; this blog consists of remarkable and in fact fine stuff for readers.

  74. Informative article, just what I wanted to find.

评论已关闭

Hi, 如果你对这款模板有疑问,可以跟我联系哦!

联系站长
赞助VIP 享更多特权,建议使用 QQ 登录
喜欢我嘛?喜欢就按“ctrl+D”收藏我吧!♡