I've seen Conditionally Render HTML in Visualforce but it seems to handle the checking on the apex side then simply reference that when determining whether to display but I don't think I can do that in my case.

function myMod(num, denom){
    alert(num % denom);
    return (num % denom) == 0;

-- stuff 

<apex:variable value="{!1}" var="rowNum"/>
<apex:repeat value="{!things}" var="thing">
-- stuff --&nbsp;
    <apex:outputPanel rendered="myMod({!rowNum}, 4)" layout="none"> <hr/> </apex:outputPanel>
    <apex:variable var="rowNum" value="{!rowNum + 1}"/>

Basically the problem is that the hr/ isn't displaying


Unlike lightning, you cannot use javascript functions inside the rendered tag of a visualforce (you might have noticed that not even the alert you have there is called), you will have to put your logic in Salesforce formula style

Try replacing your outputPanel with the following

<apex:outputPanel rendered="{!MOD(rowNum, 4) = 0}" layout="none"> <hr/> </apex:outputPanel>

For example, View

<apex:page controller="ExampleController">
    <apex:variable value="{!1}" var="rowNum"/>
    <apex:repeat value="{!things}" var="thing">
        <apex:outputPanel rendered="{!MOD(rowNum, 4) = 0}" layout="none"> <hr/>{!rowNum} {!thing}</apex:outputPanel>
        <apex:variable var="rowNum" value="{!rowNum + 1}"/>


public class ExampleController{

    public List<String> getThings() {
        return new List<String>{'Thing 1','Thing 2','Thing 3','Thing 4', 'Thing 5', 'Thing 6', 'Thing 7', 'Thing 8'};


It renders

 <hr>4 Thing 4 <hr>8 Thing 8
  • Thank you for your help! Unfortunately, it's still not showing up on the page. And yeah I noticed it wasn't calling the alert but thought it might also be because something was wrong with the de-referencing of rowNum or something
    – IanQ
    Oct 26 '17 at 20:52
  • Have you checked that {!things} have at least 4 elements? (otherwise it will not show). Oct 26 '17 at 21:15
  • Yeap! I added something to print the number of elements and it went up to like 15
    – IanQ
    Oct 26 '17 at 21:19
  • I'd say that there must be something messing up with it, try to simplify it. I'll paste a simplified version of view and controller inside my own reply to show a working example Oct 26 '17 at 21:29
  • By the way, apex:variable within an iteration element is not supported. It may or may not work correctly at any given time.
    – sfdcfox
    Oct 27 '17 at 0:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.