Template problem

I have tiddler mymacros tagged $:/tags/Macro and defining the pdf function and the p macro:

\function pdf() [[$:/temp/$1$.pdf]substitute<currentTiddler>]
\define p()
<%if [<pdf>get[state]else[missing]match[show]] %>
<$button>Close
<$action-setfield $tiddler=<<pdf>> state=hide/>
</$button>
<$transclude $tiddler=<<pdf>> $mode=block/>
<%else%>
<$button>Open PDF
<$action-setfield $tiddler=<<pdf>> state=show type="application/pdf" _canonical_uri={{{ [[https://twtalk.sirv.com/$1$.pdf]substitute<currentTiddler>] }}}/>
</$button>
<%endif%>
\end p

Then I have two normal tiddlers having as title the filename of a pdf file, but without the pdf extension. They contain the OCR text extracted from the pdf. After the OCR text I add a blank line and the call of the p macro: <<p>>. When I open the tiddler, I see the OCR text followed by a blank line and the button Open PDF. When I click the button, the pdf file is retrieved from the sirv.com site and displayed in full width below the text. That is ok. I then wanted to avoid to have to add the call of the p macro on every pdf tiddler, so I created a tiddler tagged $:/tags/ViewTemplate and added <<p>> as text. I also removed the p macro from one of the pdf tiddlers, to see whether the template works. Well, it worked, but partially: the button Open PDF was there, but when clicked it opened the pdf file in a small textarea, not filling the available width. In addition, this textarea was immediately following the button Close on the same line, instead of appearing after a newline as it was before. So I thought the problem was that the template tiddler parsed its content (<<p>>) in inline mode instead of in block mode. So I tried to replace <<p>> in the template with <$transclude $variable=p $mode=block/> but with no difference. So I am forced to append a call of macro p to all pdf tiddlers and abandon the idea of a view template. Any idea what the problem is?

A working example of the problem is available at https://twtalk.tiddlyhost.com

Clever solution to show the external pdfs. I think the issue is related to iframe wrapped into a p tag.

If you take a look at $:/themes/tiddlywiki/vanilla/base, you will see

.tc-tiddler-body > iframe {
	width: 100%;
	height: 600px;
}

So create a stylesheet tiddler with

p > iframe {
	width: 100%;
	height: 600px;
}

See also: Near fullscreen view of parsed/embeded files for example PDF

I did a little change and try to use function/procedure and it works for both cases (direct use or use in a template)

title: proc/extpdf
tags: $:/tags/Global
text:

\procedure btn-actions()
<$let tv-action-refresh-policy="always" >
<$action-listops $tiddler=<<tmpTid>>  $field="status" $subfilter="+[toggle[show],[hide]]"/>
<%if [<state>match[show]] %>
	<$action-setfield $tiddler=<<tmpTid>> type="application/pdf" _canonical_uri={{{ [[https://twtalk.sirv.com/$(currentTiddler)$.pdf]substitute[]] }}}/>
<%else%>
  <$action-deletetiddler $tiddler=<<tmpTid>> />
<%endif%>
</$let>
\end


\procedure extPDF()
\function tmpTid() [[$:/temp/pdf-files/$(currentTiddler)$.pdf]substitute[]]
\function state()  [<tmpTid>get[status]]
<$button actions=<<btn-actions>> >
	<$list filter="[<state>match[show]then[Close]else[Open]]"><<currentTiddler>></$list>
</$button>
<div class="ext-pdf">
<$transclude $tiddler=<<tmpTid>> $mode=block />
</div>
\end

ttitle: styles/extpdf
tags: $:/tags/Stylesheet
type: text/css
text:

.ext-pdf iframe {
	width: 100%;
	min-height:90vh;
	height: 100%;
}

Thanks @Mohammad, your last point was the solution! I just created the style/extpdf tiddler you suggested, but with this text, and everything works fine as expected:

iframe {
	width: 100%;
	min-height:90vh;
	height: 100%;
}

Thanks again!