Jump to content

Only show part of an ASP Include


benjancewicz

Recommended Posts

So... I think that ASP can do this, but I'm not sure.If I have an include that's pulled onto the page, is there something that I can write into the include so only a section of it shows up?I think what I do is this:The Include:

<% SUB section1 %>Item 1Item 2Item 3<% END SUB %>Item 4Item 5

The parent page pulling the include:

<% section1 %><!-- #INCLUDE FILE="includes/section1.asp" -->

The end result would be a parent page that only displays:Item 1Item 2Item 3Am I right?

Link to comment
Share on other sites

You can do it two ways. Either you can put functions in the include file, include it and call the functions, or have variables as flags where you define the variables first, then do the include. This is the first way, with functions:include file:

<%function part1()%>item 1item 2item 3  <%end functionfunction other()%>item 4item 5<%end function%>

The file that does the including would need to use function calls to display everything:

<!-- #INCLUDE FILE="includes/section1.asp" --><%part1()other()%>

This way, you would have to enclose everything inside functions, anything not in a function would be displayed immediately, and before anything that is inside a function. If you have some content that you might want to show, and other content that you always want to show, the second method is probably the best. Your include file would look like this:

<%if show_part1 = true then%>item 1item 2 item 3<%end ifif show_part2 = true then%>item 4 item 5<%end if%>always show thisitem 6item 7

The main file would look like this:

<%Dim show_part1, show_part2show_part1 = trueshow_part2 = false%><!-- #INCLUDE FILE="includes/section1.asp" -->

Link to comment
Share on other sites

  • 2 weeks later...

This is perfect!This is how I implemented it (I used the first example).On this page there is an "Events" section: https://www.fatherhood.org/Christian/That page only displays the latest event, which includes a link to "View past events."It links to a page that displays ALL the events: https://www.fatherhood.org/Christian/eventsfull.aspThanks for your help! This will change the way I design. :)Just out of curiosity (I can ask the other forum if you don't know), is there a way to do this with PHP too?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...